使用LaTeX fp包嵌套条件语句判断数值范围报错求助
LaTeX fp包嵌套条件判断错误修正
你的代码报错是因为对fp包的条件命令语法理解有误:\FPifgt、\FPiflt这类命令是TeX原生风格的条件结构,不需要用大括号包裹分支内容。你给外层\FPifgt的true分支套了大括号,导致TeX解析时把内部的\else、\fi和外层结构的配对逻辑打乱,进而触发too many }、extra \else、extra \fi错误。
修正后的完整代码如下:
\documentclass{article} \usepackage{fp} \begin{document} \def\minvalue{5.0} \def\maxvalue{10.0} % Uncomment one of these to test different scenarios \def\currentline{2.6} % \def\currentline{7.3} % \def\currentline{17.3} minvalue = \minvalue \par maxvalue = \maxvalue \par currentline = \currentline \par % First condition: if currentline > minvalue \FPifgt{\currentline}{\minvalue} Inner Loop:\par \currentline{} is greater than \texttt{minvalue} \par % Second condition nested within the first: if currentline < maxvalue \FPiflt{\currentline}{\maxvalue} \currentline{} Less than \texttt{maxvalue} \par In Range \minvalue{} to \maxvalue \par \else \currentline{} is greater than \texttt{maxvalue} \par Out of range \par \fi \else Less than \texttt{minvalue} \par \currentline{} Out of range \minvalue{} to \maxvalue \par \fi \end{document}
关键修正点:
- 移除了
\FPifgt、\FPiflt分支内容外层的大括号,让条件命令直接识别分支的起止 - 保持嵌套结构的层级对应,确保每个
\FPifXX都有对应的\else(可选)和\fi
内容的提问来源于stack exchange,提问作者grandpapocketcandy
相关产品推荐
相关产品推荐

