ifcase 吞掉字母

ifcase 吞掉字母

GCD我创建了一个在和之间切换的命令LCM。但是,它有一个副作用,就是删除命令后第二个可见字符之前的所有内容。我该如何修复这个错误?

\documentclass{article}
\newcommand{\GCDorLCM}[2]{\ifcase#1 GCD\or LCM\fi}
\newenvironment{GCDLCM_A}[3]{Find the \GCDorLCM{#1} of {#2} and {#3}.}{}
\newenvironment{GCDLCM_B}[2]{\GCDorLCM{#1}                      is maximized when \(x={#2}\).}{}

\title{}
\author{}
\begin{document}

\begin{GCDLCM_A}{1}{120}{84}
\end{GCDLCM_A}

\begin{GCDLCM_B}{0}{75}
\end{GCDLCM_B}

\end{document}

预期输出:

Find the LCM of 120 and 84.
GCD                      is maximized when x = 75.

实际产量:

Find the LCMf 120 and 84.
GCDs maximized when x = 75.

答案1

\ifcase您无关\newcommand{\GCDorLCM}[2],因此用两个参数定义它,但您只使用#1因此#2(在o这里)被丢弃。

在此处输入图片描述

\documentclass{article}
\newcommand{\GCDorLCM}[1]{\ifcase#1 GCD\or LCM\fi}
\newenvironment{GCDLCM_A}[3]{Find the \GCDorLCM{#1} of {#2} and {#3}.}{}
\newenvironment{GCDLCM_B}[2]{\GCDorLCM{#1}\hspace{4cm}is maximized when \(x={#2}\).}{}

\title{}
\author{}
\begin{document}

\begin{GCDLCM_A}{1}{120}{84}
\end{GCDLCM_A}

\begin{GCDLCM_B}{0}{75}
\end{GCDLCM_B}

\end{document}

相关内容