TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 :

share|improve this question
up vote 7 down vote accepted

instead of


you want

\csname var_#1\endcsname
share|improve this answer
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 – Charles Stewart Jul 19 '13 at 12:46
@CharlesStewart What? egreg has an answer more wordy than mine? I'm shocked. – David Carlisle Jul 19 '13 at 12:59
@DavidCarlisle - I'm sure you can draft a dreadnought-class answer to that question :) – Charles Stewart Jul 19 '13 at 14:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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