1

I construct a macro named \mymacro, and this macro would be used in two ways:

first: \mymacro, which would typeset 1

second:\mymacro*, which would typeset 2

Here is my code:

\documentclass{article}
\usepackage{ifthen}
\begin{document}
\def\mymacro#1{\ifthenelse{\equal{#1}{*}}{2}{1}}
with star: \mymacro* some text\\ % That is ok.
without star: \mymacro some text % "s" of "some" lost
\end{document} 

From the attached typeset you can see that the first charactor s of the word some is lost in the version of without star. Why?

I know \mymacro{} is a solution, but I'd like to know if there is a better way to just use \mymacro only. enter image description here

lyl
  • 2,727
  • 6
    Does this answer your question? Defining starred versions of commands (* macro) (But I must admit than I prefer the non-accepted answers.) – campa Jun 04 '21 at 13:25
  • 3
    With \def\mymacro#1{...stuff...} you define a macro that takes on argument. It will always try and absorb an argument. When you use it as \mymacro* the star gets absorbed as argument, but when you say \mymacro some more text, \mymacro grabs the following s as its argument. The classical way to define starred versions uses \@ifstar, but with new LaTeX you can use the (formerly xparse) \IfBooleanTF of \NewDocumentCommand's s type. – moewe Jun 04 '21 at 13:27
  • @moewe Would you show me an exmple how to use `@\ifstar? – lyl Jun 04 '21 at 13:32
  • 3
    Just follow campa's link to https://tex.stackexchange.com/a/4389/35864 – moewe Jun 04 '21 at 13:33

0 Answers0