How do I emit the text content of a reference in LaTeX?

前端 未结 3 821
我在风中等你
我在风中等你 2021-01-06 04:38

I have a section:

\\section{Introduction} \\label{sec:introduction}

I\'d like a link to the section where the link text is the name of the

相关标签:
3条回答
  • 2021-01-06 04:41

    You could try using

    • \newsavebox
    • \savebox
    • \usebox

    which won't save you any typeing but will give you a single authoritative source for each title


    And you might search ctan.org, I suspect this has been done already.

    0 讨论(0)
  • 2021-01-06 04:49

    As far as I know, there's no standard way to do this. Simply put, the sectioning commands don't store the names of the sections anywhere they can be easily retrieved. Yes, they're inserted into the Table of Contents (and associated auxiliary file) and marks are set, but access to those is unreliable at best and usually impossible without additional context, which is almost always unavailable by the time you need to refer back to the section.

    The code sample you posted looks like what I would write. There might be a package to automate this, but if one exists it's probably pretty hairy code since this is really not a particularly common use case. Actually, to go all grammar nazi on you the final text you're creating is incorrect; the word "introduction" should be lowercase inside the sentence, and this can't be achieved (in general) with backreferences to the actual section titles.

    I'd just suck it up and write out references like this manually. There won't be enough of them to justify automation. Of course, if you're doing something more involved than your example suggests (many auto-generated sections or something) things might be different, but if that's the case it's really a different question entirely.

    0 讨论(0)
  • 2021-01-06 04:57

    There are a couple of packages that provide this for you. nameref is distributed as part of hyperref to do this:
    http://tug.ctan.org/cgi-bin/ctanPackageInformation.py?id=nameref

    There is a more general package for cross-referencing basically anything, called zref: http://tug.ctan.org/cgi-bin/ctanPackageInformation.py?id=zref

    It's by the same author as hyperref, Heiko Oberdiek; it's the one that I would choose. Here's an example:

    \documentclass[oneside,12pt]{article}
    \usepackage[user,titleref]{zref}
    \begin{document}
    \section{Introduction of sorts.}\zlabel{sec:intro}
    Hello
    \subsection{Structure}
    We begin in `\ztitleref{sec:intro}'.
    \end{document}
    

    Note that it even removes the trailing period in the section title.

    0 讨论(0)
提交回复
热议问题