[texhax] in-section references
martin f krafft
madduck at madduck.net
Tue Oct 2 16:00:26 CEST 2007
Replying to the list...
also sprach Donald Arseneau <asnd at triumf.ca> [2007.10.01.0009 +0100]:
> > So you mean \edef\curpart{\thepart}?
>
> Yes, but that is not guaranteed to give the same result as
> \let\curpart\thepart, which is another possibility for
> what you meant. (Also, you must use \protected at edef in
> LaTeX for safety.)
Hm, if only I had a way of reading about this stuff. LaTeX is one
big mystery to me...
> 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...
> > \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
#3 page~42
The theory is that I find out whether #2 matches the current
chapter, and the way to do that is basically:
if #2 == \thechapter or ... or #2 == \thesubsubsection
then
print 'page~42'
else
print section~3.1.1
fi
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:
\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}%
\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. Am
I missing something? Is there anything I can do to fix it and make
it work with hyperref?
--
martin; (greetings from the heart of the sun.)
\____ echo mailto: !#^."<*>"|tr "<*> mailto:" net at madduck
"in diving to the bottom of pleasure
we bring up more gravel than pearls."
-- honoré de balzac
spamtraps: madduck.bogus at madduck.net
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature (see http://martin-krafft.net/gpg/)
Url : http://tug.org/pipermail/texhax/attachments/20071002/459dc1e8/attachment.bin
More information about the texhax
mailing list