STYLEREF switch

M

Marko Pinteric

Is there any switch in STYLEREF that returns its bookmark name,
e.g. {STYLREF "Heading 2" \unknown_switch} which returns _Ref9343999?

Is there any other way to get bookmark names for headings in general?

Thanks for the answers,

Marko
 
S

Stefan Blom

As far as I know, the STYLEREF field doesn't rely on bookmarks. It
simply references the "current" text or number formatted in a
particular style. For more, see Word Help.
 
S

Suzanne S. Barnhill

A heading doesn't have a bookmark until you have inserted a cross-reference
or created a TOC. Once you've done that, you can select the heading and go
to Insert | Bookmark, check the box for "Hidden bookmarks" and select the
radio button for "Location." The _Ref or _Toc that is highlighted will be
the one for the selected heading.
 
G

G.G.Yagoda

I don't know if this is what you're looking for, but there's an
undocumented STYLEREF field that repeats just the number of the last
used Heading style. The formula is ( STYLEREF 1 \s ) where Heading 1
is the level you want.

If your last Heading 1 reads "ARTICLE III," for example, then the
STYLEREF field above will return just "III." Same idea as a SEQ field
with the \c switch that continues the last number.
 
J

John McGhie

Marko:

Please share with us why you need this information?

You "could" get to this through VBA, but it's difficult and laborious, so if
you tell us what you are going to use the information for we may be able to
suggest a better approach.

Cheers

Is there any switch in STYLEREF that returns its bookmark name,
e.g. {STYLREF "Heading 2" \unknown_switch} which returns _Ref9343999?

Is there any other way to get bookmark names for headings in general?

Thanks for the answers,

Marko

--

Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <[email protected]>
Consultant Technical Writer
Sydney, Australia +61 4 1209 1410
 
S

Suzanne S. Barnhill

I think it relates to his simultaneous question about cross-references, the
answer to which probably makes this one academic.
 
M

Marko Pinteric

Unfortunatelly the answer to question about cross-references didn't help
me, so maybe this is relevant.

Best regards, Marko
 
M

Marko Pinteric

John,

Thanks for offering your help. I have a very common problem and no
solution for it. In technical documentation for projects in civil
engineering (at least here in Slovenia), you have very strict
specification for footer content. If the Heading on the page is of
level 2, then footer needs to display heading 2, and if Heading on the
page is of level 1, then footer needs to display heading 1. As far as I
know, nobody in Slovenia has succeeded to automatize this thing and
everybody are making separate sections for EACH heading 1 or heading 2
part of document. Which is, as you might suspect, a laborous effort!

Anyways, by looking on Internet I found something that was very good
aproximation for what I was looking for. It was the following code field:

{IF {STYLEREF "Heading 2" \n }<{STYLEREF "Heading 1" \n } {STYLEREF
"Heading 1" \n } {STYLEREF "Heading 2" \n }}

Obviously, the idea is to display LAST heading available from the point
of view of code field. This has one big mistake, for all Headings 1
that come before FIRST Heading 2, it displays that FIRST Heading 2. The
reason lays in the fact that in such cases Word - after not finding any
Heading 2 BEFORE particular code field - starts searching AFTER
particular code field. So you get

1 3.1
2 3.1
3 3.1
3.1 3.1
3.2 3.2
4 4
4.1 4.1

I found a better solution though, that is code:

{IF "{STYLEREF "Heading 1" \n}.2"<{STYLEREF "Heading 2" \h} {STYLEREF
"Heading 1" \n} {IF {STYLEREF "Heading 1" \n}>{STYLEREF "Heading 2" \n}
{STYLEREF "Heading 1" \n} {STYLEREF "Heading 2" \n} }

The idea is that first Heading 2 has "1" for second number, so first I
check if current Heading 1 is smaller that level 1 of (possibly first)
Heading 2. This gives the following result:

1 1
2 2
3 3.1
3.1 3.1
3.2 3.2
4 4
4.1 4.1

This is much better, but both pages with "3" and "3.1" get "3.1" in the
footer. After a closer inspection, the reason is very simple. On both
pages that contain "3" and "3.1" you have the same value for {STYLEREF
"Heading 1" \n} ("3") and {STYLEREF "Heading 2" \n} ("3.1") so you
CANNOT DISTINGUISH between two pages!!! Therefore solution has to be
found outside of the scope of STYLEREF code.

Another idea I got is to put hidden code in the beginning of the
document, which finds PAGE NUMBER of the first Heading 2 and then refer
to it. It is no problem to find the title of first Heading 2. Being in
the beginning of the document, {STYLEREF "Heading 2" \n} will certainly
found first Heading 2 name ("3.1"). But how to get page "4" out of
Heading name "3.1"? If I can manage to do THAT, then I have a solution
to the problem and possibly the whole civil engineering society of
Slovenia will be grateful.

So this is the problem. Do you find it interesting enough to solve it?

Best regards,

Marko.
 
M

Marko Pinteric

But is it possible to force Word to make bookmarks (possibly with the
same name as the Heading)? Let's say to make {BOOKMARK {STYLEREF
"Heading 1" \n}} part of every Heading 1 title and {BOOKMARK {STYLEREF
"Heading 2" \n}} part of every Heading 2 title?

Regards, Marko
 
S

Suzanne S. Barnhill

I think you're heading down a blind alley with that idea. I didn't see what
you were trying to do with the bookmarks, but I think that idea is just not
going to fly.
 
K

Klaus Linke

Hi Marko,

What if you'd apply a character style "charHeading" to all headings (level 1 and
2), and use a { styleref charHeading \n }?

Greetings,
Klaus
 
K

Klaus Linke

Sorry, I didn't see that John McGhie had already suggested that in another
thread.
Did you try it? Didn't it work?

Klaus
 
M

Marko Pinteric

He did suggest that? I didn't see that.

Idea hears interesting, but I just don't know how to do that!

Could you give me step-to-step instruction?

Best regards,

Marko
 
K

Klaus Linke

Not sure what part makes the difficulty...

Create a character style without any special formatting, call it charHeading,
and apply it to all headings 1 and 2.

Then { styleref charHeading \n } should display the numbering of the previous
charHeading paragraph (... a bit surprising, since charHeading is a character
style and numbering is a paragraph property, but it seems to work fine).

It's a bit of work to apply it, and there's unfortunately no good way to do that
automatically as you type a new heading, but at least it should work.

Please post back if anything isn't clear.

Klaus
 
C

Charles Kenyon

I think the term for this in the current slang is...

s w e e e e t !

This one is a keeper and should go on the MVP FAQ some place.
 
K

Klaus Linke

Not sure if that hadn't been John McGhie's idea... If not, it was a glorious
misunderstanding <g>.

I still love the styleref method.
Robert M. Franz has posted a lot of variations on them in the German groups, and
there's hardly anything you can't do.

If you don't have a proper hierarchy of headings, it should still work with the
expression Marco posted
{IF {STYLEREF 2 \n }<{STYLEREF 1 \n }
{STYLEREF 1 \n } {STYLEREF 2 \n }}
if you insert hidden headings where they should have appeared:

1
1.1 (formatted hidden)
2
2.1 (formatted hidden)
3
3.1
3.2
4
4.1
....

Regards,
Klaus
 
K

Klaus Linke

[show last heading number on page in the footer, no matter whether it's from a
"Heading 1" or a "Heading 2", using legal numbering 1., 1.1., ... for the
heading styles]



I think I found a better StyleRef field expression for the job.

You still have to insert a hidden "Heading 2" after the first "Heading 1" if
it's missing.
And in that case, you may also have to choose "different first page" and insert
a different header, if the "1.1" hidden chapter is shown.

But you don't need to do anything for the rest of the chapters.
It always shows the last heading on the page. I've not found a similar
expression for the first heading.

The expression uses an undocumented exploit.

{ styleref 1 \n \l }{ if{ styleref 2 \n \l \@"d"}={ styleref 1 \n \l } ".{
styleref 2 \n \l \@"M" }" "" }

First, it inserts the last "heading 1" chapter number on the page.

And in the second expression, I've used an undocumented "feature" I've found:
{ styleref 2 \n \@"d"} returns the main chapter number of the heading 2 (say 7
for 7.4.),
{ styleref 2 \n \@"M"} returns the heading 2 subchapter number (say 4 for
7.4.).
But this only works reliably for chapter numbers up to 31(?) and subchapter
numbers up to 12, since it interprets the subchapter heading number as a date
and then extracts the day/month.

So the second field expression prints a dot and the sub-chapter number if the
main chapter number for the last "heading 2" is identical to the last "heading
1" on the page (that is, if there's a heading 2 following the last heading 1 on
the page), else nothing.

If you have more than 12 main chapters, you can use another exploit for which
I've found no explanation. Maybe the field gurus from MailMerge have one?
{ styleref 2 \n \#"0" } returns the sum of the main chapter number and the
subchapter number (say, "11" for subchapter number "7.4.").
So
{={ styleref 2 \n \#"0" }- { styleref 2 \n \@"M" }}
returns the main chapter number (without limit).

The new and improved version (unlimited chapter numbers, up to 12 subchapters
per main chapter):
{ styleref 1 \n \l }{ if{={ styleref 2 \n \l \#"0" }-{ styleref 2 \n \l
\@"M" }}={ styleref 1 \n \l } ".{ styleref 2 \n \l \@"M" }" "" }

Klaus
 
K

Klaus Linke

.... and another idea for chapter numbering like
1
2
2.1
2.2
3
....

You could interpret the chapter numbers as decimal numbers, and use =Max to find
the maximum:
{ =Max({ styleref 1 \n \l }, { styleref 2 \n \l }) }

You might need the same "1.1" hidden "Heading 2" and different first page header
as in the previous post.

It doesn't work in my German version though, since the decimal "point" is a
comma over here :-(

Regards,
Klaus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top