Share via

Using Fields to Generate Specialized "Breadcrumbs"

Anonymous
2017-04-24T15:43:22+00:00

I am developing a template to be used with a MSc thesis which requires "breadcrumbs" to be placed in the header.    Even pages will show the page number in the upper-left, with the Chapter Number: Chapter Title in the upper right.  Odd pages show the numbering of the most recent Heading 2 and the Title of the Heading 2.  The caveat is that the first page of the chapter is to have no "breadcrumbs" at all - since the chapter is numbered there.  This, I have gotten to work so far (through the separation of sections, the use of "Different Odd & Even Pages," the use of Styles, and some complex use of Fields), for the first four chapters.

When I add in a fifth chapter, however, the Fields appear to break, informing me that "Error! Bookmark not defined."  My intent is to fully automate the breadcrumbs/heading such that a user can add chapters as needed, using the proper Styles to autopopulate the TOC and breadcrumbs.  I do not expect the user of the template to manipulate the headings or by having to create new sections after the first page of each chapter.

Because there is not an easy way for a Field to check if a Heading Type is used on the current page, I use an IF statement and compare the current page number to a PageRef that is linked to the StyleRef for Heading 1.  As I mentioned earlier, though it's not an intended use of PageRef, it worked for the first four chapters.

The Fields I am using for the breadcrumbs are:

Even page: { IF "{PAGE}"="{PAGEREF{STYLEREF 1}}" "" "{STYLEREF "ChapterNum"}: {STYLEREF 1}"}

Odd page: {IF "{PAGE}"="{PAGEREF{STYLEREF 1}}" "" "{IF "{PAGEREF{STYLEREF 2}}"="ERROR!*" "{STYLEREF 2 \N} {STYLEREF 2}" "{IF {PAGEREF{STYLEREF 2}} < {PAGEREF{STYLEREF 1}} "{STYLEREF "ChapterNum"}: {STYLEREF {STYLEREF 1}" "{STYLREF 2 \N} {STYLEREF 2}"}"}"}

Yes, I know it's a mess.  The "<" IF statement on the Odd-Page is set so that should a Heading 2 not be used for the first couple pages, the Heading 2 from the previous chapter is not used.

The page numbering is fine, so I am not showing them.

Is there any reason that it would work initially, but break later?  I understand that using PageRef in a Header may have issues - is this a symptom of a known bug?  Is there a better way to do this than using the Fields in this way?

There is evidence of having a similar issue with Heading 2; but an IF statement checking for an error appeared to solve that issue.  For some reason, using a similar IF "ERROR!*" for Heading 1 doesn't have any effect.

And to be clear, I have tried updating the page by pressing "F9".

Thanks!

-Keith-

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2017-04-25T05:46:29+00:00

The thing is that the equality "{PAGE}"="{PAGEREF{STYLEREF 1}}" will function (i.e. will evaluate to False) in almost all cases, so on the even pages you will get the text you want on all pages except the first in a chapter. It's that it works on that first page that is the mystery. Similarly on the odd pages, the first equality will function on all except the first page.

You can certainly email the doc to me - I believe my email is in my profile which you can reach by clicking on my name hereabouts, but will check later.

You can in a sense "step through" bits of a field code by selecting (say) one field within a nested code and pressing shift-F9 to display the result. It's easy to overselect. Also, It may not work so well in a header/footer.

I'm not aware of a field code that does exactly what you want. Perhaps someone else can think of one. I am a little wary of putting complex field code constructions in headers because

 (a) Word (or Windows Word, at any rate) seems to update its headers quite frequently (which is one reason why some things work in headers immediately when you have to F9 them in the document body.) But at a certain point, this can become a performance issue and cause problems for the document's user, particularly as a document gets longer.

 (b) the main mechanism I know for doing it relies on the user putting the right SEQ fields in the right paragraphs, all the time. That's a big ask. It's also simpler if you can rely on the correspondence between a section and (in this case) a chapter remaining simple - i.e. no extra Word sections to introduce a page layout change and so on, and simple page numbering (no restarts, so probably no chapter-page numbering).

However, suppose for example you could get your user to insert a { SEQ s0 \r{ PAGE #0 } \h } field in every Chapternum paragraph, a { SEQ s1 \r{ PAGE #0 } \h } in each heading 1 para, and so on, then you should be able to test, in a header, whether a Chapternum style paragraph exists on the current page, via

{ IF  {PAGE #0 } = { SEQ s0 \c } ....}

and similarly for the H1/H2 styles.

Ideally, when using a scheme like this the user would be able to insert exactly the same fields in every (heading paragraph), so they don'y have to think about it so much, and so (for example) they could use the outliner more easily to promote/demote stuff. Usually that requires a whole bunch of fields. In this case yoou might be able to simplify a little by using H1,H2,H3 instead of a non-heading style + H1/H2 and leveraging the \s switch of the SEQ field, but I haven't actually worked it through.

Was this answer helpful?

0 comments No comments

4 additional answers

Sort by: Most helpful
  1. Anonymous
    2017-04-25T10:40:16+00:00

    And for further clarification.  The way I am solving the problem is by asking the users to add the Chapter Title as a bookmark (using Insert -> Bookmark) to maintain consistency.  I believe this is reasonable - although I think there are some clever ways around that even (perhaps by using underscores in the title/bookmark, but coloring the underscores as a background color to hide.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2017-04-25T10:02:56+00:00

    Thank Peter!

    Just to summarize our email messages for the general public - yes, it does appear that the titles of the chapters had been set up as bookmarks (prior to my working with the document).  As you mentioned, this would not be sustainable for several reasons, but one big limitation is that the bookmark names can't require spaces.

    You had mentioned that in your line of work you have favored macro writing.  It is definitely a possibility, but unfortunately hits a weak point in my MS Suite proficiency.  Guess I'd need to start somewhere!

    This explains why my Fields were working initially, but would not interface with new material.  You have taught me how to analyze a small piece of a field at a time (which will help troubleshooting in the future).  And there is not a field that is easily set up to recognize whether a certain Style exists on the current page.

    I appreciate your help with this!

    -Keith-

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2017-04-24T21:43:39+00:00

    Peter, you understand correctly - though I have purposefully not set up any cross-references/bookmarks as that would hinder the template's ease of use.

    I spent a lot of time trying to find a way to find a field that would perform: "If a certain style exists on this page only, print nothing, otherwise print some other text."  In reading the PAGEREF description, I knew it shouldn't have worked, but I was curious what output I would get giving it a STYLEREF as an argument.  I was surprised to find it give me the page number I was expecting - and it propagated correctly through the entire template text (4 chapters of Example).  So, along with you, I am intrigued enough that it actually worked.

    Within the template, I provided non-formatted text in a format that would exemplify how to add a chapter to the template with in-text instructions (add Section Break before the Chapter and apply proper styles... ta da!).  After the Heading worked for the first section (ie four chapters), I was most dismayed that it failed.

    Here I must lament there is no easy way to step through a Field in the same way you can an Excel formula, to see how each component evaluates for troubleshooting like this.  My proxy has been to use another space and add in each Field independently to see how they evaluate.  In doing so, as expected, "{PAGEREF {STYLEREF 1}}" evaluates to "ERROR! Bookmark not defined."  As you mentioned, I wouldn't be so perturbed by the message except that it had worked previously.  I thought I would try to be clever and anticipate the error, by beginning the entire statement with an {IF "{PAGEREF {STYLEREF 1}}" = "ERROR!*" "" "All the original Odd Page Field Code"}.  Interestingly, rather than evaluating to the blank, it still insists that the "Bookmark is not defined."

    I'd be happy to pass along the file to see if it behaves the same way for you as well.

    I know that I am trying to shoehorn an inappropriate function into doing something it's not intended for.  Is there any field that allows: "If a certain style exists on this page only, print nothing, otherwise print some other text"?

    -Keith-

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2017-04-24T18:01:54+00:00

    Just as an initial observation, the question I have is not so much "why doesn't it work for chapter 5?", but "why does it work for the existing chapters?"

    Because PAGEREF wants a bookmark, i.e. { PAGEREF bookmarkname }. So suppose we take { PAGEREF { STYLEREF 1 } }. For that to work, { STYLEREF 1 } need to resolve to the name of a bookmark. But { STYLEREF 1 } is the text in a paragraph with Heading style Heading 1 (in an English-language copy of Word). If that text is a bookmark name, then the pageref will point to the page where that bookmark is located. But why would it be?

    Once you have inserted a cross-reference to a heading (say the heading text), then there will be a bookmark, say "_Ref480822308" that will reference the paragraph text. But then you would need { PAGEREF "_Ref480822308" } to reference that, and it's not obvious how you could derive the bookmark name that happened to have been created to reference that heading. Unless you are inserting suitable bookmark names manually.

    Otherwise, I would have thought that almost every { PAGE } = { PAGEREF { STYLEREF 1 } } comparison is going to result in a non-match.

    Did I misunderstand?

    Was this answer helpful?

    0 comments No comments