Page 1 of 1
A couple cross-reference questions
Posted: 2015-06-26 23:44:08
by brsnyder
Hello --
I am a new user and have looked in the manual, but can't find the answer to these questions.
-- Is there a way to search for cross-references?
-- I know I can highlight a cross-reference and double-click it to get to the target. Is it possible to highlight text that is the target of a cross-reference? So I can tell by looking if text is used as a cross-reference? I thought it created auto-bookmarks but I've turned on that highlighting and it isn't doing anything. Or do I have to manually go to the target and create a bookmark? (I did do that and it works but I'm wondering if that can be automatic.)
-- Is it possible to navigate from the target back to the cross-reference that points to that target? (Probably only relevant if I can tell by looking that text is in fact the target of a cross-reference.) I created one cross-reference and it created a "_goBack" bookmark, but I created a second one and it didn't create a similar bookmark.
Thanks -- Barbara
Re: A couple cross-reference questions
Posted: 2015-06-30 01:39:57
by adryan
G’day, Barbara et al
Welcome to the forum, Barbara.
Nisus Writer has two manuals, both accessible from the Help menu: Nisus Writer Pro Help and the Macro Language Reference.
I have never had occasion to use cross-references myself, but I observe that the Macro Language Reference (see “CrossReference Object”) includes tools to do the things you want. No doubt someone with more experience with cross-references will have some macros you could use or could easily whip them up for you.
Cheers,
Adrian
Re: A couple cross-reference questions
Posted: 2015-06-30 02:35:43
by phspaelti
Hello again Barbara,
for a start be aware that in Appearance Preferences you can set a highlight color for Cross-References to help you spot them more easily.
As for the reverse, finding all text that has been cross-referenced, things are a bit trickier. Nisus allows 5 types:
- Bookmark
- List item
- Table
- Footnote/Endnote
- TOC item
Internally they are all handled via bookmarks. So Nisus seems to bookmark the items you want to cross-reference to on the fly. For that it uses those hidden bookmarks you were asking about in the other thread. Nisus also has a display color for bookmarks (including a separate color for auto-named bookmarks), but this doesn't seem to highlight everything that is bookmarked. For example it doesn't seem to highlight a list item or a table that has been used as a cross-reference.
If you wanted to find all those bookmarks you could do that via a macro. I just tried something like that, and I have to say I was surprised to find that not all cross-referenced bits actually show up in the list of bookmarks. That is if I run through the list of cross-refererences and get their bookmarks there are some which are not included in the list Document.allBookmarks.
Anyhow, just because a bit is bookmarked (hidden or not) does not mean that is is being cross-referenced somewhere, but one could easily create a macro that goes through the cross-references in the document and creates a list of the bits that are bookmarked and have a cross-reference pointing at them.
Re: A couple cross-reference questions
Posted: 2015-06-30 02:47:05
by phspaelti
Here is code to select all currently cross-referenced bits (i.e., all bits with cross-references pointing at them):
Code: Select all
$doc = Document.active
$doc.setSelection $doc.allCrossReferences.arrayByMakingValuesDoCommand('bookmark')
Re: A couple cross-reference questions
Posted: 2015-06-30 14:49:33
by brsnyder
Thanks, Philip. That is great but it still doesn't show my where the xref is coming from. I suppose there could be multiple xrefs pointing to any particular bookmark. It's just an academic exercise at this point anyway.
I did create a macro to create a hidden bookmark, then tried to create a second macro to create an xref from selected text to that bookmark. I couldn't figure out how to add the xref. But I was able to do it with a link. If you could tell me how to edit this macro to add an xref instead of a link, I would be most grateful. It's the counterpart for link.apply that I couldn't get to work as an xref.
$targetBookmarkName = Read Clipboard 'bookmark' #populated in createdHiddenBookmark macro
$link = Link.newWithBookmarkName $targetBookmarkName
$link.apply
Delete Clipboard 'bookmark'
Thanks -- Barbara
Re: A couple cross-reference questions
Posted: 2015-07-01 02:30:25
by phspaelti
Hi Barbara, this discussion seems to have spread across about three different threads.
Let me just say again, I don't understand why you are first creating hidden bookmarks and then trying to create the cross-reference later. Do you really need so many cross-references to random bits of text—as opposed to list items or other bookmarkable things—in your document, that you are worried that your bookmark list will be too long?
Anyway, in that case it seems you want to create a separate category of (hidden) bookmarks, and then you need to create a macro that collects these bookmarks and allows you to select from the list at cross-reference time. It should be noted that hidden bookmarks are going to be ugly if you have a lot of them. The name of the bookmark is some random variable, and the displayName, which is basically the selected text may not be unique. In addition you will have to recreate the ability to choose what the cross-reference will look like (page number, line number, selected text, etc.). In effect this all just re-creates the cross-referencing feature that Nisus already makes for you.
Here is my blunt code for this kind of thing. It doesn't try to solve the above problems in any realistic way. It also doesn't check the insertion point, it just inserts at the cursor.
Code: Select all
$doc = Document.active
$anchors = Array.new
foreach $bm in $doc.allBookmarks
if $bm.isHidden
$anchors.push $bm
end
end
$list = $anchors.arrayByMakingValuesDoCommand('displayName')
$name = prompt options 'List of Anchors', 'Choose one to cross-reference', 'OK', $list
$i = $list.indexOfValue $name
$xref = CrossReference.newWithBookmark $anchors[$i]
$xref.setReferenceType 'PageNumber'
$sel = TextSelection.active
$sel.text.insertAtIndex $sel.location, $xref
Re: A couple cross-reference questions
Posted: 2015-07-01 02:43:38
by phspaelti
brsnyder wrote:Thanks, Philip. That is great but it still doesn't show my where the xref is coming from. I suppose there could be multiple xrefs pointing to any particular bookmark. It's just an academic exercise at this point anyway.
If it's an academic exercise, then I'm not sure I need to respond. But hey, I'm an academic
Indeed that's the whole problem with the bookmark-xref relationship. It's a one-to-many relationship. Think of the bookmarks as celebrities and the xrefs as fans. The celebrity isn't responsible for knowing where the fans are.
If you really needed this kind of thing you could write a macro that made a full list of all the bookmark-xref pairs. Presumably this would be some kind of inventory type document, showing whatever info about these guys that you think you needed. But for the most part I don't understand the need. The cross-reference already shows you the linked info. That is the
whole point of the xref. Sometimes there is some worry about deleting a bookmark which has been linked to. But Nisus does alert you to such things, with a [Referenced content missing] alert at least.
Re: A couple cross-reference questions
Posted: 2015-07-01 11:00:15
by brsnyder
Hi and thanks again.
Maybe using the link model instead of xref will help explain what I am thinking of in terms of hidden bookmarks. Think of it as an HTML <anchor> tag. I think xref is the wrong metaphor, now that I've discovered links.
Let's say I have a paragraph - here's a random example:
"If you really needed this kind of thing you could write a macro that made a full list of all the bookmark-xref pairs. Presumably this would be some kind of inventory type document, showing whatever info about these guys that you think you needed. But for the most part I don't understand the need."
Now I don't want anything there bookmarked - it's just a paragraph. But somewhere else I might want to say "As Philip pointed out..." and I want "pointed out" to link to that paragraph. I have to have a bookmark there in order to point to it. So it will have to be a hidden bookmark. That's my use case.
I had to write two macros to do this, the first to create the hidden bookmark and the second to create the link. If there was a way to create hidden bookmarks directly in the UI, especially in the Add Bookmark As dialog, those macros wouldn't be necessary.
Maybe this is actually a feature request, and those hidden bookmarks would have to show up in the Bookmark list dropdown when creating the link, but not in the navigator.
Hope that clarifies. And if there is already a way to do this that I haven't found, please advise!
Thanks -- Barbara
Re: A couple cross-reference questions
Posted: 2015-07-01 20:54:37
by phspaelti
Yes, I see that what you seem to be using this for is more like hyperlinks. Cross-references usually take the form of "…as seen in example 23", "…as discussed on page 45", etc. where the whole headache is in getting the, potentially changing, numbers to show up correctly. But importantly the numbers have to be actual document objects. So cross-references usually link to list items, TOC items, or tables, etc. which is exactly what the cross-reference provides for. In my dissertation, which was written in Nisus Classic, I had hundreds of bookmarks, all of them named. But that was because that was the only way to do cross-references back then. Now I would just cross-reference to list items, and I probably wouldn't have any bookmarks at all.
Anyhow, I understand what you are saying, but I don't understand what you have against using regular bookmarks for what you are doing. As a feature request I might suggest the following two ideas:
1. Allow for multiple bookmark collections. This would be a bit like different index styles. The Navigator and the cross-reference dialog could then allow one to flip through the different collections.
2. Allow for cross-referencing to a location using Find/Replace or the user-interface. In the cross-reference dialog you could have a further option Find/Replace. This would bring up the Find/Replace dialog and you can search for a location to use as the cross reference target. That would mean you wouldn't need to bookmark anything at all. Or have the cross-reference (or linking) dialog allow you to switch to the document and let you choose the location in the document at that time (with a confirmation windoid). After you select the location, click [OK] and the cross-reference/link is made.