I have defined the following command


and I'm calling it from a document in the following way:

... \gsubselector{a,i} : \gsubselector{b,j} there is ...

I expect an output such as:

... $s_{a,i}$ : $s_{b,j}$ there is ...

however, judging from the output pdf that I've got using 'pdfTex', the output corresponds to the following code:

... $s_{a,i,:}$ $s_{b,j,t}$ here is ...

Am I doing something wrong in the definition? Thanks!

  • Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – mvkorpel Jul 16 '14 at 8:17
  • 3
    You are only supplying one argument to \gsubselector, but have defined it with two. Are you intending to do \newcommand\gsubselector[1]{$s_{#1}$}\gsubselector{a,i} or perhaps \newcommand\gsubselector[2]{$s_{#1,#2}$}\gsubselector{a}{i}? – Joseph Wright Jul 16 '14 at 8:20
  • 3
    Arguments in LaTeX are not a comma separated list use {a}{i} – daleif Jul 16 '14 at 8:20

You just need


because a call such as


will make a,i as the only argument to \gsubselector, so the macro substitution will give


as required.

However, I don't think this is a good definition. In your code snippet you type

... \gsubselector{a,i} : \gsubselector{b,j} there is ...

and this input might result in the colon being at the start of a line, which is quite certainly unwanted.

My impression is that this colon is part of a math formula. I believe it's better to segregate math in its proper environment, so



... $\gsubselector{a,i} : \gsubselector{b,j}$ there is ...

so the colon will be properly interpreted as a math relation symbol. There's still a chance that TeX will break a line after the colon. If this happens, try adding \nolinebreak after the colon

... $\gsubselector{a,i} :\nolinebreak \gsubselector{b,j}$ there is ...

There are chances that TeX will be able to find a different way of breaking a paragraph; if not, it's a welcome occasion for polishing your prose and reword the text. Good typography requires human help to the machine.

Don't add \nolinebreak in every instance: TeX is usually reluctant to break a line after a relation symbol and does it only when the alternative is, at its eyes, worse. But line breaking is not just splitting a long line and stretching or shrinking the interword spacing: semantic considerations are also important and the machine knows nothing about them.

  • normally i just need \gsubselector{a,i}. There will be only a few cases where I might need the colon, so the \nolinkebreak will do. Thanks a lot! – Martí Bosch Jul 16 '14 at 9:06



If it doesn't help create a complete example.

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.