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

The following works as expected:

\newcommand{\engl}[2]{#1 (en. \textsl{#2})\index{en-ro}{#2}}

However, what I want to achieve would be a * version of it which only adds to the indices, without the visible text, something like:

\newcommand{\engl*}[2]{#1 (en. \textsl{#2})\index{en-ro}{#2}\term{#1!#2}\term{#2!#1}}

Of course, this does not work (the pdf is compiled, but with lots of warnings which were not there with the original definition), so I've tried something equivalent with xparse:

    {#1 (en. \textsl{#2})\index{en-ro}{#2}\term{#1!#2}\term{#2!#1}}%

which doesn't work either.

How to properly create such a command and its * counterpart?

share|improve this question
At least related: Defining starred versions of commands – clemens Jan 13 '13 at 17:27

From the xparse 'point of view', a star is an additional optional argument. Thus #1 is a boolean representing 'there is a star', while #2 and #3 are the two mandatory arguments. This leads to

  #2 (en. \textsl{#3})\index{en-ro}{#3}%




where I've shared code as far as possible and only provided a TRUE case for the presence of a star.

share|improve this answer
+1. Really enlightening. – Flavius Jan 13 '13 at 17:34

This is tagged and but doesn't depend on xetex, and you don't really need xparse for star forms which are reasonably well supported by latex. I changed \term to \textrm just so it ran.

Just define the nostar and star forms, then define your top level command to switch between them


\newcommand{\englnostar}[2]{#1 (en. \textsl{#2})\index{en-ro}{#2}}

\newcommand{\englstar}[2]{#1 (en. \textsl{#2})\index{en-ro}{#2}\textrm{#1!#2}\textrm{#2!#1}}





share|improve this answer
What if the two versions would have different number of parameters? – Flavius Jan 13 '13 at 17:25
It would be against the latex syntax guidelines to make the number of arguments depend on a star (or an optional argument) no standard latex command does that. However there is no connection between the two comnands they can have any definition and argument structure. \engl itself just looks for a * (not the pther arguments) and then calls one or other command. – David Carlisle Jan 13 '13 at 17:48

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.