Take the 2-minute tour ×
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.

I'm trying to figure out how best to define an alias. I have some moderately complicated variable names, such as $p^{i,j}_{t}$, and having to type them over and over again is a pain. More importantly, if I decide later to change my naming convention, I'd have to go back and search replace in my whole document, which seems ridiculous. I've tried to use this method:


but this method is not powerful enough. First of all, I cannot use it in Math mode, and would have to define another command


which seems redundant.

Second of all, latex doesn't know that it's supposed to insert a whitespace after I use the command in a text environment. If I force a whitespace in the command, I cannot use the command just before punctuation like full stop, or comma.

Any suggestions? Thank you!

share|improve this question
Welcome to TeX.SX! A tip: You can use backticks ` to mark your inline code as I did in my edit. –  Adam Liter Nov 26 '13 at 2:36
It is a math expression, so it should always be written with $-signs, embedding the $ will make the code harder to read. Define it without $'s and use $\varn$. –  daleif Nov 26 '13 at 8:13

2 Answers 2

You can use \ensuremath Running for cover, egreg will come soon.


\varn  \qquad    $\varn$

Here is how \varn{} is used in text again \varn.


Fir the second part, you may insert an empty atom {} after \varn like \varn{} when you need a space. This is the usual behaviour. Thre is also xspace package, but it may fail some times.

\varn  \qquad $\varn$

Here is how \varn is used in text again \varn.


enter image description here

As noted by egreg, it won't take much work to write $\varn$ over \varn. It is also more symatec for you identify math code. So better define \newcommand*{\varn}{p^{i,j}_{t}} and use $\varn$.

share|improve this answer
Thank you very much! –  Halfdan Nov 26 '13 at 3:00
Write 100 times on the blackboard "I'll not mention \ensuremath for two months" and send a photo on chat when you're done. Seriously: what's the advantage of ...how \varn is... over ...how $\varn$ is? I see none. –  egreg Nov 26 '13 at 8:57
@egreg You remind me of my school days :-) Really here no advantage. I will add it to the answer. Thanks. –  Harish Kumar Nov 26 '13 at 9:24
I will not downvote, but the two concepts you just used --- \ensuremath{...}\xspace --- are of the ugliest things you can ever do in LaTeX, pretty much fighting usage of `~\\~\` for vertical white-space. –  yo' Nov 26 '13 at 14:05
@daleif you mean across ~\\~\\? Well, you don't wanna know what one comes across as a typesetter... –  yo' Nov 26 '13 at 21:45

Please, never try to "get rid of the 'additional dollars'." First, you easily mis-interpret your math as text. Second, this then leads to doing things like \varn=0, which, in text mode, becomes $p^{i,j}_{t}$=0, and this get completely wrong spacing. So, you should define


and then use it as in:

We have that $\varn=0$ if and only if the guy $\varn$ is really zero.
share|improve this answer

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.