Page 1 of 1

Refer to endnote more than once

PostPosted: Thu Apr 17, 2014 5:18 am
by mladlow
I'm programmatically creating some endnotes in a document, which looks roughly like (in word):

Code: Select all
blah blah blah ^1
text text text ^2
---------------------------
^1 Source Document
^2 Source Document


Ideally, I'd like to have this look like:

Code: Select all
blah blah blah ^1
text text text ^1
---------------------------
^1 Source Document


As far as I can tell from the specification this seems to be impossible. So two questions.
1. Is this actually impossible or am I reading the spec wrong?
2. Is there another way of achieving roughly the same functionality?

Thanks for any thoughts!

Re: Refer to endnote more than once

PostPosted: Thu Apr 17, 2014 11:10 am
by jason
Use a NOTEREF field plus a suitable bookmark:-

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
    <w:p >
      <w:r>
        <w:t>blah blah blah</w:t>
      </w:r>
      <w:bookmarkStart w:id="0" w:name="note1"/>
      <w:r>
        <w:rPr>
          <w:rStyle w:val="EndnoteReference"/>
        </w:rPr>
        <w:endnoteReference w:id="1"/>
      </w:r>
      <w:bookmarkEnd w:id="0"/>
    </w:p>
    <w:p >
      <w:r>
        <w:t>text text text</w:t>
      </w:r>
      <w:r >
        <w:fldChar w:fldCharType="begin"/>
        <w:instrText xml:space="preserve"> NOTEREF  note1 \f \h  \* MERGEFORMAT </w:instrText>
        <w:fldChar w:fldCharType="separate"/>
      </w:r>
      <w:r>
        <w:rPr>
          <w:rStyle w:val="EndnoteReference"/>
        </w:rPr>
        <w:t>i</w:t>
      </w:r>
      <w:r>
        <w:fldChar w:fldCharType="end"/>
      </w:r>
    </w:p>
 
Parsed in 0.002 seconds, using GeSHi 1.0.8.4

Re: Refer to endnote more than once

PostPosted: Fri Apr 18, 2014 2:26 am
by mladlow
I just tried this. It's not quite the same as an actual reference to the endnote right? For one thing I am using superscript numbers as my footnote format, so I would have to use "1" instead of "i" as my text in the w:t block.

Also, that text, while it would continue to have the bookmark, wouldn't update if I added another endnote higher in the document?

I feel like you'd also want the bookmark pointing to the actual endnote and not the first reference to the endnote.

Thanks for the example though.

Re: Refer to endnote more than once

PostPosted: Fri Apr 18, 2014 8:22 am
by jason
mladlow wrote:that text, while it would continue to have the bookmark, wouldn't update if I added another endnote higher in the document?


It would update in Word. If you wanted to update it using docx4j, you'd have to write suitable code.

In any case, this is the "Word-way" to do it.

If you want total control, you could simulate endnotes without actually using actual endnote XML. Simulating endnotes would be easier than simulating footnotes, since they don't have to be positioned at the bottom of each page.