locked
Cross reference refer text instead number after saving RRS feed

  • Question

  • Hello,

    I'm writing a .ODT document on MS Word 2017 and have problem with Cross reference.

    Cross reference refer text instead number after saving.

    Example:

    --------

    Have text:

    "Lorem ipsum dolor sit amet:

    1. One;
    2. Two;
    3. Three;

    consectetur adipiscing elit, "2"(cross reference on second item of numbered list items with the corresponding paragraph number options "Paragraph number")."

    Then I saving the document, closing and open again.

    After update cross reference I take this:

    "Lorem ipsum dolor sit amet:

    1. One;
    2. Two;
    3. Three;

    consectetur adipiscing elit, "Two;"(cross reference on second item of numbered list items without any the corresponding paragraph number options)."

    -------

    Why the corresponding paragraph number options get cleared after save?

    Does anyone know how to make this work?

    Friday, October 12, 2018 10:15 AM

Answers

  • Edited...

    I think I can tell you why it goes wrong, but it isn't so obvious how to make it work (I have added one possibility at the end of this text). 

    The overview is that
     a. if you use (say) LibreOffice to insert a similar reference to the paragraph number, it uses an XML attribute to specify that you wanted the paragraph number rather than the paragraph text. e.g. something like this:

    text:reference-format="number"

     If you wanted the text "Two:", LibreOffice would save this instead:

    text:reference-format="text"

     Finally, if you wanted the page number of the page containing the paragraph, LibreOffice would use this:
    text:reference-format="page"

    That's quite straightforward IMO.

     b. However, natively, Word uses a field code to insert the cross-reference. For the text, it would typically insert a hidden bookmark to "cover" the text, let's call it _Ref52715222, then the following field code to reference the "Two:" text:

    { REF _Ref52715222 }

    When Word saves that to .odt format, I believe it correctly uses 'text:reference-format="text"'

    When Word inserts a reference to the number, the field code looks like this:

    { REF _Ref52715222 \r }

    When Word saves that to .odt, it just seems to ignore the \r and still uses 'text:reference-format="text"'

    When you re-open the .odt document in Word, initially Word does not overwrite the text "2", but the field code you see has lost the \r :

    { REF _Ref52715222 }

    So when you select and update the field, e.g. using ctrl-F9, the "2" is replaced by the bookmarked text, i.e. "Two:".

    It seems that Word *should* retain the effect of the \r by using  'text:reference-format="number"' instead. But it doesn't. Further, if you actually modify the XML in the .odt to use "number" instead of "text", Word does not interpret it using

    { REF _Ref52715222 \r }

    as you might hope. Instead, it uses

    { PAGEREF _Ref52715222 }

    which is also the wrong thing.

    So unfortunately you do not seem to be able to fix this behaviour by modifying the XML before re-opening the .odt file.

    But in addition, because word uses "text" instead of "number", this does not even work properly when you open the .odt in (say) LibreOffice. Just as in Word, it looks OK until LibreOffice "updates" the cross-reference.

    This looks like an error to me, and it looks fixable, so you might want to pursue the possibility of a fix. It is also possible that it happens because Word's ODF converter originally targetted an earlier version of ODF and has never been updated, or that there are other complications which make it difficult for Microsoft to get this right.

    On workarounds:
     a. for LibreOffice, you could probably fix the problem by modifying the XML post-save. Personally, I think the only realistic way to do that would be to use code. I was only able to do it by hand here because I only looked at very simple cases. I would expect it to be much more difficult in the general case.

    Further, unless you know that all References to bookmarks whose names look like "_Refnnnnnnnnn" should be references to a number, you would have to know which ones to change. The same is true if you want to be able to fix the problem in Word.
     b. If you do not care about losing the link between the reference and the original paragraph number, a solution would be to replace the reference field codes by their results prior to saving the document. 
     c. Other than that, it seems that from Word's perspective, you would need to put something in the document that would enable you to restore the \r option that is lost when round-tripping via the .odt format. None of the approaches I can think of is at all simple to use - it would require that the user knows that the document has to be fixed, and knows how to apply the fix. In the simplest case, if you can assume that all fields that reference hidden, Word-created bookmarks should be REF\r fields, you could use a Find/Replace option like this to re-insert the \r:
    Find what:-
    _Ref^#^#^#^#^#^#^#^#^#
    Replace with:-
    ^& \r

    (I am assuming a certain format for the Word-generated REF bookmarks).

    Otherwise, you could apply a character style to each REF field that needs to be restored. e.g. create a style called "backslashr" that just applies the "Default paragraph font", and apply it to all the { REF bookmark \r } fields. Then, when the document is re-opened, used the above Find/Replace, but for the Find what text, use Format->Style to specify the backslashr style. 

    If you can use VBA, you could wrap that into a suitable macro. But personally, I think it is a lot to ask of your users whichever way you do it.


    Peter Jamieson



    • Edited by Peter Jamieson Saturday, October 13, 2018 10:57 AM Further info/suggestions
    • Marked as answer by Edward.Rylsky Tuesday, October 23, 2018 9:58 AM
    Friday, October 12, 2018 5:07 PM

All replies

  • Edited...

    I think I can tell you why it goes wrong, but it isn't so obvious how to make it work (I have added one possibility at the end of this text). 

    The overview is that
     a. if you use (say) LibreOffice to insert a similar reference to the paragraph number, it uses an XML attribute to specify that you wanted the paragraph number rather than the paragraph text. e.g. something like this:

    text:reference-format="number"

     If you wanted the text "Two:", LibreOffice would save this instead:

    text:reference-format="text"

     Finally, if you wanted the page number of the page containing the paragraph, LibreOffice would use this:
    text:reference-format="page"

    That's quite straightforward IMO.

     b. However, natively, Word uses a field code to insert the cross-reference. For the text, it would typically insert a hidden bookmark to "cover" the text, let's call it _Ref52715222, then the following field code to reference the "Two:" text:

    { REF _Ref52715222 }

    When Word saves that to .odt format, I believe it correctly uses 'text:reference-format="text"'

    When Word inserts a reference to the number, the field code looks like this:

    { REF _Ref52715222 \r }

    When Word saves that to .odt, it just seems to ignore the \r and still uses 'text:reference-format="text"'

    When you re-open the .odt document in Word, initially Word does not overwrite the text "2", but the field code you see has lost the \r :

    { REF _Ref52715222 }

    So when you select and update the field, e.g. using ctrl-F9, the "2" is replaced by the bookmarked text, i.e. "Two:".

    It seems that Word *should* retain the effect of the \r by using  'text:reference-format="number"' instead. But it doesn't. Further, if you actually modify the XML in the .odt to use "number" instead of "text", Word does not interpret it using

    { REF _Ref52715222 \r }

    as you might hope. Instead, it uses

    { PAGEREF _Ref52715222 }

    which is also the wrong thing.

    So unfortunately you do not seem to be able to fix this behaviour by modifying the XML before re-opening the .odt file.

    But in addition, because word uses "text" instead of "number", this does not even work properly when you open the .odt in (say) LibreOffice. Just as in Word, it looks OK until LibreOffice "updates" the cross-reference.

    This looks like an error to me, and it looks fixable, so you might want to pursue the possibility of a fix. It is also possible that it happens because Word's ODF converter originally targetted an earlier version of ODF and has never been updated, or that there are other complications which make it difficult for Microsoft to get this right.

    On workarounds:
     a. for LibreOffice, you could probably fix the problem by modifying the XML post-save. Personally, I think the only realistic way to do that would be to use code. I was only able to do it by hand here because I only looked at very simple cases. I would expect it to be much more difficult in the general case.

    Further, unless you know that all References to bookmarks whose names look like "_Refnnnnnnnnn" should be references to a number, you would have to know which ones to change. The same is true if you want to be able to fix the problem in Word.
     b. If you do not care about losing the link between the reference and the original paragraph number, a solution would be to replace the reference field codes by their results prior to saving the document. 
     c. Other than that, it seems that from Word's perspective, you would need to put something in the document that would enable you to restore the \r option that is lost when round-tripping via the .odt format. None of the approaches I can think of is at all simple to use - it would require that the user knows that the document has to be fixed, and knows how to apply the fix. In the simplest case, if you can assume that all fields that reference hidden, Word-created bookmarks should be REF\r fields, you could use a Find/Replace option like this to re-insert the \r:
    Find what:-
    _Ref^#^#^#^#^#^#^#^#^#
    Replace with:-
    ^& \r

    (I am assuming a certain format for the Word-generated REF bookmarks).

    Otherwise, you could apply a character style to each REF field that needs to be restored. e.g. create a style called "backslashr" that just applies the "Default paragraph font", and apply it to all the { REF bookmark \r } fields. Then, when the document is re-opened, used the above Find/Replace, but for the Find what text, use Format->Style to specify the backslashr style. 

    If you can use VBA, you could wrap that into a suitable macro. But personally, I think it is a lot to ask of your users whichever way you do it.


    Peter Jamieson



    • Edited by Peter Jamieson Saturday, October 13, 2018 10:57 AM Further info/suggestions
    • Marked as answer by Edward.Rylsky Tuesday, October 23, 2018 9:58 AM
    Friday, October 12, 2018 5:07 PM
  • Thanks for answer.

    When Word inserts a reference to the number, the field code looks like this: { REF _Ref52715222 \r }.

    When I edit XML and change text:reference-format from "text" to "chapter". MS Office doesn't see that cross reference at all, and I don't get why, but in OpenOffice that cross reference is correct.

    When I edit XML and change text:reference-format from "text" to "number".  I get a PAGEREF, I don't need this.

    Monday, October 15, 2018 8:22 AM
  • I agree. I could not see a way through that works for everything, and certainly not a simple way.

    What I was suggesting was that the problem occurred whether you reopen in Word or LibreOffice (I haven't checked this in OpenOffice so do not know if Libre and Open have diverged in this area), that you can fix it in LibreOffice as long as you know which cross-references to fix, but that that fix does not work in Word.

    I have since found [MS-OODF3].pdf, "Office Implementation Information for ODF 1.2 Standards Support" (see, e.g. https://msdn.microsoft.com/en-us/library/hh695327%28v=office.12%29.aspx?f=255&MSPPError=-2147217396 ), which says that Microsoft Word does not support the "chapter" or "number" values for the text:reference-format attribute, and doesn't even "support" the "text" value!



    Peter Jamieson

    Monday, October 15, 2018 9:45 AM
  • Hi Edward,

    What is the detailed version of Word you are using? ( Create a blank document in word , click File > Account to check product information. Click About Word to get detailed version and build number) As far as I know, there is no such Office 2017 product.

    You can create a new document, copy and paste the contents of the test section to see if the cross-reference is displayed correctly.

    Does it appear normal when you reopen this document before? Is it a problem that the paragraph number options are cleared after updating the cross-reference? If so, how did you operate specifically? Can you provide some screenshots to help me understand your problem?

    For more information about cross-reference in Word, please refer to Create a cross-reference.

    If you have any question about Office, please feel free to let me know.

    Best Regards,
    Herb Gu

    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Microsoft Team

    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams
    Monday, October 15, 2018 10:09 AM
  • Hi, Herb.

    I was wrong, I'm using Word 2016, 16.0.4738.1000.

    My problem is that the paragraph number options are cleared after closing and opening document. While document is opened references are working.

    I can't attach pictures or use links, because my profile is not verify yet.

    Monday, October 15, 2018 11:11 AM
  • Different programs often interpret different file formats slightly different; this is not unusual (although it is frustrating of course). Apparently, in this case, Word does not fully support cross-references created in the *.odt format.

    I don't think there is anything you can do except post feedback in the Uservoice forum at https://word.uservoice.com.


    Stefan Blom, Microsoft Word MVP

    Monday, October 15, 2018 1:59 PM
  • Hello, Stefan.

    But page "Differences between the OpenDocument Text (.odt) format and the Word (.docx) format" said that the Cross References is Supported, what means Word features are fully supported in the OpenDocument (.odt) format.

    Wednesday, October 17, 2018 6:14 AM
  • You are quite right that the article at https://support.office.com/en-us/article/differences-between-the-opendocument-text-odt-format-and-the-word-docx-format-d9d51a92-56d1-4794-8b68-5efb57aebfdc seems to suggest 100% compatibility for cross-references. However, this isn't correct, obviously. See also the article for which Peter Jamieson provided a link: https://msdn.microsoft.com/en-us/library/hh695327%28v=office.12%29.aspx?f=255&MSPPError=-2147217396.


    Stefan Blom, Microsoft Word MVP


    Wednesday, October 17, 2018 7:31 AM
  • In my view, a lot comes down to what is understood by "supported". It either means "that's what the software does", in which case the article you reference is wrong, or it means "that's what Microsoft intends the software to do, and it will modify the software if it does not do that". I understood that as far as products in mainstream support were concerned, Microsoft means the latter. If so, it would probably try to fix the problem for Word 2016 but not (say) Word 2010. But (a) I may be wrong about that and (b) these days I do not know what the best way to report an error in the software that should be fixed, rather than a request for a new feature. I hope one of the Microsoft people here can clarify that - perhaps the service link that Stefan gives is for errors as well as Wishlist items - there is certainly no harm in posting there, but I suggest that if you do, you consider that this is an error, and provide a link to this conversation.

    Peter Jamieson

    Wednesday, October 17, 2018 7:45 AM
  • Thanks all of you for your answers.
    I will be use Find/Replace for my problem.
    Tuesday, October 23, 2018 9:58 AM