News:IMPORTANT MESSAGE! This forum has now been replaced by a new forum at http://forum.eastgate.com and no further posting or member registration is allowed. The forum is still accessible via read-only access for reference purposes. If you wish to discuss content here, please use the new forum. N.B. - posting in the new forum requires a fresh registration in the new forum (sorry - member data can't be ported).

I am looking to export a BibTex file. I have created attributes for each field that will be made for each citation in the final BibTex exported file. Each of those attributes has been put into $KeyAttributes.

I then have created a BibTex citation template that so far looks like this.

It is nearly there but I can't get the actual attribute values for the attributes listed, in $KeyAttributes. So I need to find a way to get the listed attribute values and have them in the right field. I also need to exclude the three $citeinessay, $citetype and $nickname attributes, as they are for internal Tinderbox use.

NB: The ^if^ statement is for not exporting attributes that have no data. I will get that done as soon as getting the attributes values in the template is done.

The only bit not achieved is the line breaks after each attribute's entry which seems to be a problem in the evaluation of do() or the resolution of ^if()^. Still, I hope this moves things forward. I'm off on the road for a few days so can't progress this further just now.

Can you post a link to your test file? It looks like the note being exported has no key attributes. My post used code copied from a working test. Not sure I kept the latter so it would help to see your file.

In your last example, I notice the output implies the note used to create it has no $citetype or $nickname. Are you exporting the right note?

Ah, I see (this is why having a reference file helps!). In your "References" agent, move the Rule's code to the 'Action" box, so it's applied to the agent's children (i.e. the matched reference notes).

Your 'BiBtex' export template is set, sensibly, in the 'Reference' prototype. so when you open 'test-reference' in HTML view you should see the data as I do. I don't have/use BibTeX so can't advise on the layout of the export file.

To do:

Getting the per-attribute data to have line breaks after each item has defeated me. However, it may not matter to BibTeX. Unless Eastgate can point out an angle I've missed, getting line breaks may require tweaks the TB app.

I see $note' is a key attribute but also possibly intended to be hard coded as the last entry in the export. So you may need to add 'note' to the list of deletions from $MyExportSet and then amend the export template accordingly.

Note - do ensure to read the linked articles in this reply as they hold much of the fine detail of the answers you seek.

Quote:

^if(\$$1)^$1= {^value(\$$1)^},^endIf^

Using do() or ^do()^call, the first parameter given is the name of the macro. The second and subsequent parameters form the first and subsequent data inputs passed the specified macro.

Within the macro, the inputs are referred to as $1, $@, etc. Wherever a $N is inserted the literal value of the input (i.e. the do() input value), thus above the $1 is inserting an attribute name passed to the macro. But, we need the overall result to be an attributereference (i.e. a $-prefixed name). In a macro a $ already has a special meaning, so to insert an actual dollar-sign character we 'escape' it with a back-slash (the red code above). So is input one is "SomeName" the macro code \$$1 returns the string "$SomeName". White space matters in this context; if the macro code were \$ $1 the string returned becomes "$ SomeName" - which isn't, of course, a valid attribute reference!

$KeyAttributes is a Set. We are using the Set.replace() to create set that excludes the 3 attribute names before passing the result to $MyExportSet. The replace string is a regular expression - description of the fine workings of these is a subject on its own; if you're new to regex, I'd read up the general subject via Google.

We need $MyExportSet as if we try to do the next step by nesting code (inserting the right side of the above where $MyExportSet is in the code below) it doesn't work. There are limits to how deeply TB will drill down into code in terms of evaluating things. There's no hard as fast limit - before you ask, you just need to experiment. Plus, when designing this sort of code, it's useful to have interim attribute values so you can check the result of each step is what you assumed it to be.

This is a hack to get around the fact that action and export code lack a loop function, e.g. for(x, x < y; x=x+1) sort of thing. We need to turn every item in $MyExportSet into a discrete string. OK, Set.format(), in its 4-argument syntax, lets us supply list-prefix/item-prefix/item-suffix/list-suffix for each item in the set. In fact, we only need list prefix/suffix but there's another road-block that I address with a macro. Each Set item's output needs to use the current list item value more than once. So, in the format() code's argument #2 and #3 we wrap the item name in an eval(do()) call, split between [2] and [3] like so: [eval(do(] and [))]. For Set item "SomeAttribute" we pass in

eval(do("export-list","SomeName"))+

…representing #2[Set item value]#3, and receiving back:

eval(^if($SomeName)^SomeName= {^value($SomeName)^},^endIf^)+

Great, we've now tricked format() into inserting each set item value not once, but three times, into the per-item output.

The outer wrapper takes the string+string+string+ output from format() and turns it into a single string.

Footnote. Why use ^code^ in the macro and not action code and evaluate before export. Well, it seems that's pushing eval() and macros further than they're currently (v5.9.3) designed to go - ergo the outstanding problem with TB no letting me get line returns where I want them in $ExportString. AS you may guess I explored a lot of blind alleys in getting to the above code (as the edges of action code aren't documented - aTbRef is effectively what we know, or believe, is true).

Sorry for the long post. This stuff isn't simple (in execution) so please don't shoot the messenger if it's hard to follow! As said previously, try breaking the task into steps and check at each one that progress thus far is what you expect.

Mark A.'s code looks very elaborate, and I would most likely understand it better if I saw it implemented. Plus, I'm very interested in exporting BibTeX as well (to avoid redundancies with other bibliography programs).Do you have a more recent version of your sample file that we could look at?

@Sebastian. 3/4? You're doing well , as it's not exactly shallow-end TB use. I've tried to avoid classing the missing line return issue as a 'bug' because it's only my assumption that it ought to be possible - I've not seen a definitive statement that it should work. Whatever, past experience is that these sort of edge cases get fixed in subsequent releases.