I took some habits with my sciences reports so I developed some personalized commands.

First, I define in the preamble all the variables that I need like this:


Then I begin all my equation labels by "eq:" like in this example :

  \za = \frac{1000.-T}{34}

And finally, I set a command which allows me to make a reference from a variable to its definition inside the environment equation :


In this example, za will point to the previous equation :

  \cvba = \eref{za}{\za}+12

My problem is that I would like to make my new command eref a little bit easier and lighter to use such as it takes only one parameter.

I tried to define it like this :


Obviously it doesn't work because the \# is understood as a specific character.

So my question is : "How could I concatenate two strings to make a new command?"

If it can helps, the names of my variables can change, for example they could be \var_varname such as he new command would looks like :


instead of


you want

\csname var_#1\endcsname
  • It worked perfectly (without the underscore in the variable name)! Thanks.
    – GuillaumeM
    Jul 19 '13 at 12:37
  • For the ones who are interested, here is the good command : \newcommand{\eref}[1]{\hyperref[eq:#1]{\csname #1\endcsname}}
    – GuillaumeM
    Jul 19 '13 at 12:43
  • It is worth linking to egreg's luminous explanation of how \csname is 'is used to build commands from "variable parts"', so I shall: tex.stackexchange.com/a/39382/175 Jul 19 '13 at 12:46
  • @CharlesStewart What? egreg has an answer more wordy than mine? I'm shocked. Jul 19 '13 at 12:59
  • @DavidCarlisle - I'm sure you can draft a dreadnought-class answer to that question :) Jul 19 '13 at 14:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.