Latex lookup table

I have a bunch of automatically generated LaTeX code with hypertrags of the form "functionname_2093840289fad1337", that is, the name of the function with the addition of a hash. I would like to refer to these functions from the rest of the document, referring only to the name of the function, which, as I know, is unique. I would like the search function to look something like this:

\hyperdyperlink{functionname} 

which emits

 \hyperlink{functionname_2093840289fad1337}{functionname} 

Note that I cannot calculate the hash, but I am ready to write a table that maps each function name to the function name + hash. What is the best way to write such a function?

+6
latex lookup-tables control-structure
source share
2 answers

It works?

  \ makeatletter
     \ newcommand \ hashlink [2] {%
       \ @namedef {hashlink- # 1} {# 2}%
     }
     \ newcommand \ hyperdyperlink [1] {%
       \ hyperlink
         {# 1 _ \ @ nameuse {hashlink- # 1}}
         {#one}%
     }
     \ hashlink {functionname} {2093840289fad1337}
     \ hyperdyperlink {functionname}
     \ makeatother

(tested.)


Later: To deploy code that depends, if you have defined the purpose of the link, you can write something like

  \ newcommand \ hyperdyperlink [1] {%
       \ @ifundefined {hashlink- # 1} {%
         [whatever else you want to do]
       } {%
         \ hyperlink {# 1 _ \ @ nameuse {hashlink- # 1}} {# 1}%
       }%
     }

( Update: oops; this was pretty broken, like the first post, sorry. Now fixed, hopefully.)

+7
source share

Since function names are unique, could you define the goals of the hyperlink without adding a hash?

Alternatively, you can create a new LaTeX macro for each function. The code that generates LaTeX code can do this by outputting the code as follows:

 \newcommand{\linkFoo}{\hyperlink{foo_2093840289fad1337}{foo}} \newcommand{\linkBar}{\hyperlink{bar_4323812312asf1342}{bar}} 

Then use \linkFoo and friends in your handwritten part.

You can also implement the correct lookup table using TeX macros, if you want - see this thread for an example - but this solution is pretty easy and easier to understand (IMHO).

+5
source share

All Articles