[texhax] in-section references

Donald Arseneau asnd at triumf.ca
Wed Oct 3 14:04:38 CEST 2007


martin f krafft <madduck at madduck.net> writes:

> Replying to the list...
> 
> also sprach Donald Arseneau <asnd at triumf.ca> [2007.10.01.0009 +0100]:
> > > So you mean \edef\curpart{\thepart}?
> > but your best test is to insert 
> > \show\curref
> > \show\refpart
> > and note the differences.
> 
> If I do that, I just get a runaway argument error. But I can use
> standard "printf" debugging with \typeout, read on...

They have to work, wherever \typeout would work.  The problem is
\typeout doesn't report the real definition because it expands.
You could do:
\typeput{\meaning\curref; \meaning\refpart}

> > >   \def\curref{#2}%
> > 
> > I'm not sure what you are giving as #2,...
> 
> \rrefx{section}{\ref{some-term}}{page~\pageref{some-term}}
> 
> So
>   #1 section 
>   #2 3.1.1

NO!  #2 = \ref{some-term} !

Try \protected at edef\curref{#2}, but I suspect that gives differences from
the plain characters "3.1.1".

> Now here is the function again, this time with \hbox{} (which Tom
> originally included), which appears to be necessary as \ref{}
> outputs it when it expands the reference:

Yes, that's what I thought.  This also depends on the definition of \p at section
and others.

> \newcommand{\rrefx}[3]{%
>   \protected at edef\curchapter{\thechapter\hbox{}}%
>   \protected at edef\cursection{\thesection\hbox{}}%
>   \protected at edef\cursubsection{\thesubsection\hbox{}}%
>   \protected at edef\cursubsubsection{\thesubsubsection\hbox{}}%
>   \protected at edef\curref{#2}%
>   \def\refsame{#3}%
>   \def\refother{#1~#2}%

\show\curref
\show\cursubsection

>   \ifx\curchapter\curref\refsame%
>     \else\ifx\cursection\curref\refsame%
>       \else\ifx\cursubsection\curref\refsame%
>         \else\ifx\cursubsubsection\curref\refsame%
>           \else\refother%
>         \fi%
>       \fi%
>     \fi%
>   \fi%
> }%
> 
> And I finally got it working *iff* I disable the hyperref package.
> If it's enabled, I guess \ref{} generates something else and the
> match fails. In fact, typeout outputs:
> 
>   DEBUG: \ref {section:deb-term-nonfree}A\hbox {}A.2\hbox {}A.2.0\hbox {}A.2.0.0\hbox {}
> 
> so the \ref is substituted later, which breaks my approach. 


Try \edef\curref{#2}, which will expand \ref, but I suspect it
will give an error in expansion.

> Am I missing something?

Probably you are missing a pre-existing package like "smartref". 


-- 
Donald Arseneau                          asnd at triumf.ca


More information about the texhax mailing list