Citation Cross-reference problem
Posted: 2021-06-20 01:43:33
In the thread http://www.nisus.com/forum/viewtopic.php?f=18&t=11866 Þorvarður asks about how to do build an automatic citation using the AIAA Citation Style.
Using the referenced style guide as input I have created the following test file: Using this style I will discuss how to approach this problem. Þorvarður gives a nice description of how to do this step by step:
But an issue that comes up here is how cross-references work. Since we are going to need to use the bookmarked text to be used as the cross-reference we will need to worry about the format of the citation references in the text. The AIAA specification allows all of the following cases:
Once this has been cleared up, we can be more specific about the relevant task; from the reference we will need to bookmark just the actual number, since if we bookmarked "[4]" as a whole we would end up with things like this "[4]-7]" or "[4], p. 35]".
A next technical issue comes up when creating the cross-reference; we will need some way to get the relevant bookmark. If we create all bookmarks all at once it will hard to know for sure how to access the bookmark for the reference "[4]" since the name for the bookmark will be auto-generated. Thus to solve this it will be better to create the bookmarks one at a time and save them in an Array or Hash as we create them, so we can recall the relevant bookmark when we need it.
Thus we should modify the above code as follows:
So first I have modified the find expression to select only the number inside the bracket. This also give us a handy reference to the bookmark, which are stored in an Array called "$references". The bookmark to reference "[4]" will be stored in "$references[4]".
With this problem solved we can now consider how to insert the cross-references.
Inserting cross-references in the macro language is a two-step process.
Using the referenced style guide as input I have created the following test file: Using this style I will discuss how to approach this problem. Þorvarður gives a nice description of how to do this step by step:
- Find all the references which are marked by bracketed numbers [1] at the beginning of the line
- Bookmark the references
- Find the citations in the text
- Cross-reference them
Code: Select all
Find All '^\[\d+\]', 'Ea'
Add Bookmarks
- [4]
- [4, 5]
- [4-7]
- [4, p.35]
- [4, pp.25-28]
Once this has been cleared up, we can be more specific about the relevant task; from the reference we will need to bookmark just the actual number, since if we bookmarked "[4]" as a whole we would end up with things like this "[4]-7]" or "[4], p. 35]".
A next technical issue comes up when creating the cross-reference; we will need some way to get the relevant bookmark. If we create all bookmarks all at once it will hard to know for sure how to access the bookmark for the reference "[4]" since the name for the bookmark will be auto-generated. Thus to solve this it will be better to create the bookmarks one at a time and save them in an Array or Hash as we create them, so we can recall the relevant bookmark when we need it.
Thus we should modify the above code as follows:
Code: Select all
$doc = Document.active
$referenceSels = $doc.text.find '(?<=^\[)\d+(?=\])', 'Ea'
$references = Array.new
foreach $sel in $referenceSels
$num = $sel.substring
$bookmark = Bookmark.newAutonamedAddedToTextSelection @false, $sel
$references[$num] = $bookmark
end
With this problem solved we can now consider how to insert the cross-references.
Inserting cross-references in the macro language is a two-step process.
- Create the Cross-reference object
- Insert it into the text using ".insertAtIndex"