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 have defined the following command

\newcommand{\gsubselector}[2]{$s_{#1,#2}$}

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!

share|improve this question
    
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 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 at 8:20
3  
Arguments in LaTeX are not a comma separated list use {a}{i} –  daleif Jul 16 at 8:20

2 Answers 2

You just need

\newcommand{\gsubselector}[1]{$s_{#1}$}

because a call such as

\gsubselector{a,i}

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

$s_{a,i}$

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

\newcommand{\gsubselector}[1]{s_{#1}}

and

... $\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.

share|improve this answer
    
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 at 9:06

Try

 \newcommand\gsubselector#1{\expandafter\GSUBelector#1!!} 
 \def\GSUBelector#1,#2!!{\ensuremath{s_{#1,#2}}}

If it doesn't help create a complete example.

share|improve this answer

Your Answer

 
discard

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.