STYLEREF switch

K

Klaus Linke

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 }) }


Drats: 3.9 is greater than 3.10, so this hack allows for even less sub-chapters
than the previous one...

8-/ Klaus
 
K

Klaus Linke

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.

That's true if Word didn't find a "Heading 2" anywhere above, and goes off
hunting for one further down.

You can use the hidden "1.1." heading 2 mentioned in my post below.
Or you can start chapter numbering at zero, and put a dummy title page at the
beginning of the doc, with a Heading 1 and a Heading 2, which you throw away
after printing. So it doesn't matter if it displays the wrong footer, and you
don't need to mess with "different first page".

It would be really nice if there were a way to figure out where the styleref was
found (above the page, on the page, below the page). But the \p switch of the
styleref field doesn't seem to work in headers and footers.

Regards,
Klaus
 
M

Marko Pinteric

You can use the hidden "1.1." heading 2 mentioned in my post below.
Or you can start chapter numbering at zero, and put a dummy title page at the
beginning of the doc, with a Heading 1 and a Heading 2, which you throw away
after printing. So it doesn't matter if it displays the wrong footer, and you
don't need to mess with "different first page".
Yes, but the problem is that these ghost headings appear in table of
contents, which I do not want to do.
It would be really nice if there were a way to figure out where the styleref was
found (above the page, on the page, below the page). But the \p switch of the
styleref field doesn't seem to work in headers and footers.
Yes, that would definitely solve my problem.

Regards, Marko
 
M

Marko Pinteric

Klaus said:
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
Sorry, that wouldn't work for chapter 1. You'd get

1 1.1
1.1 (hidden) 1.1
2 2
2.1 2.1
3 3
3.1 3.1

With STYLEREF method [which is - I agree - really stylish :cool:], all
headers 1 before first header 2 are problem.

Marko
 
M

Marko Pinteric

Klaus,

First of all lots of thanks for your interest in this problem. However,
EVERY solution that was proposed either by you or me has one problem.
It does not distinguish between first heading 2 and appropriate
heading 1. E.g.

Heading STYLEREF 1 STYLEREF 2
1 1 2.1
2 2 2.1
2.1 2 2.1
3 3 2.1
3.1 3 3.1

You see, on pages that contain first heading 2 (2.1) and appropriate
heading 1 (2) the results for STYLEREF 1 and STYLEREF 2 are IDENTICAL.
On the other hand, the result of field code must be DIFFERENT. Using
switches like \@"d" and \@"M" won't help because results of those
calculations will be still the same for pages with 2 and 2.1.
If there is an udocumented STYLEREF switch that would help distinguish
between these two pages, that would enable automatic solution.

So I still think this is most elegant solution and uses only documented
switches (it works at least if you have less than 10 headers 1):

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

The first IF checks if header 1 is smaller than first part of header 2
(no problem with commas). If so, simply put header 1. Otherwise use
standard STYLEREF formula.

However, it has the above mentioned problem, which - it seems - cannot
be solved. There is no code field which would tell if you are dealing
with page containing 2.1 or 2.

Best regards,

Marko.
 
K

Klaus Linke

Hi Marco,
First of all lots of thanks for your interest in this problem.
However, EVERY solution that was proposed either by
you or me has one problem.
It does not distinguish between first heading 2 and appropriate
heading 1. E.g.

Yes, and that will keep being a problem if you allow Word to search downwards
(because it doesn't find a heading further up).
That's the reason I introduced the hidden Heading 2 at the start -- probably
best in a throwaway "Chapter 0". Though you are right that you'd need to delete
that manually from the TOC.
So I still think this is most elegant solution and uses only documented
switches (it works at least if you have less than 10 headers 1):

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

Should that be an \n instead of a \h? And you should keep aware that the number
of "Heading 2" subchapters in a chapter should be less than 10 for the first
"IF".

Before this thread I wasn't thinking much about how the chapter numbers are
compared.
With "1, 1.1, 1.2, 2 ...", they are compared as decimals (if a dot is your
decimal separator), or as strings (if it isn't).
With "1., 1.1., 1.2., 2., ..." legal numbering, they are compared as dates.

Neither of these is really right for comparing chapter numbers, and it may mean
you and I are getting different results in some cases.
The first IF checks if header 1 is smaller than first part of header 2
(no problem with commas). If so, simply put header 1. Otherwise use
standard STYLEREF formula.

It doesn't work for me 100%:
If you have some subchapters further down, say "4.3", "4.4", ... "4.12", then
the expression
IF "{STYLEREF 1 \n}.2"<{STYLEREF 2 \n} will be true (4.2 < 4.3 ...), and you get
"Heading 1" instead of "Heading 2".

You could minimize that problem by using ".9" instead of ".2".
However, it has the above mentioned problem, which - it seems - cannot
be solved. There is no code field which would tell if you are dealing
with page containing 2.1 or 2.

As long as Word is allowed to search downwards, that seems to be true.

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