简体   繁体   中英

Alternative input to LaTex newcommand

Is there an alternative way to enter multiple arguments to LaTex newcommand constructions? I have defined

\newcommand{\nuc}[2]{\ensuremath{^{\text{#1}}\text{#2}}}

and I would like to call the command through

\nuc{12,C}

and not

\nuc{12}{C}.

I have created other commands with even more arguments and my poor pinky can't handle all the brackets.

Thanks!

Maybe you will like it.

\def\nuc #1,#2.{\ensuremath{^{\text{#1}}\text{#2}}}

Sample of using:

\nuc 12,C.

Note. Use the dot at the end.

I like to praise perltex for defining complicated functions. This isn't complicated, but you can extend it quite impressively.

%myfile.tex
\documentclass{article}
\usepackage{perltex}

\perlnewcommand{\commafrac}[1]{
  $input = shift;
  @inputs = split(/,/, $input);
  return "\\ensuremath{\\frac{$inputs[0]}{$inputs[1]}}";
}

\begin{document}
One half is $\commafrac{1,2}$.
\end{document}

Compile with perltex --latex=pdflatex myfile.tex . I know that \\frac wasn't your example, but I find it a visually appealing one.

Use plain TeX \\def :

\makeatletter
\newcommand*{\nuc}[1]{\nuc@#1\@nil}
\newcommand*{\nuc@}{}
\protected\def\nuc@#1,#2\@nil{\ensuremath{^{\text{#1}}\text{#2}}}
\makeatother

As fas as I know \\nuc{12}{c} is the only way. If you don't want to put all the "}{"s, let the editor do it. Write \\nuc{12,c} first, then replace all commas with "}{"s.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM