簡體   English   中英

LaTex newcommand的替代輸入

[英]Alternative input to LaTex newcommand

有沒有其他方法可以為LaTex newcommand結構輸入多個參數? 我已經定義

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

我想通過調用該命令

\nuc{12,C}

並不是

\nuc{12}{C}.

我創建了其他帶有更多參數的命令,但是我可憐的小指無法處理所有括號。

謝謝!

也許您會喜歡。

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

使用樣本:

\nuc 12,C.

注意。 在末尾使用點。

我喜歡稱贊perltex定義了復雜的功能。 這並不復雜,但是您可以對其進行擴展。

%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}

使用perltex --latex=pdflatex myfile.tex編譯。 我知道\\ frac不是您的示例,但我發現它是一個外觀吸引人的示例。

使用普通的TeX \\def

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

據我所知, \\nuc{12}{c}是唯一的方法。 如果您不想放置所有的“} {”,請讓編輯器執行。 首先編寫\\nuc{12,c} ,然后將所有逗號替換為“} {”。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM