我正在使用polynom
多项式长除法包。例如:
\documentclass{article}
\usepackage{polynom}
\begin{document}
\polylongdiv{x^3-x^2+d}{x-2}
\end{document}
请注意,那里有另一个变量d
。polynom
处理得很好,但调用它1d
。
有什么方法可以扩展代码以便我可以编辑吗1
?
答案1
与任何 Latex 包一样,polynom
其源本质上是一个可用程序,因此您可以修改它:
尚未经过广泛测试但是...
\documentclass{article}
\usepackage{polynom}
\begin{document}
%\tracingall
\makeatletter
\def\pld@AccuPrint@#1#2{%
\ifnum #2=\@ne \ifnum#1=\@ne\zz\else\number #1\fi\else \frac {\number #1}{\number #2}\fi }
\def\zz{\expandafter\zzz\romannumeral`\^^@}
\def\zzz{\futurelet\tmp\zzz@}
\def\zzz@{\ifx\tmp\let\else1\fi}
\polylongdiv{x^3-x^2+d}{x-2}
% check 1 is still printed if no following variable
\polylongdiv{x^3-x^2+1}{x-2}
% Heiko
\polylongdiv{1+d}{1}
\end{document}
答案2
最后一行打印为
\pld@R {4}{1}+\pld@R {1}{1}\pld@S {d}{1}
\pld@R
具有 的含义\pld@Rational
。因此,以下示例重新定义了\pld@Rational
。如果分子和分母相等,并且\pld@S
后面有一个符号 ( ),\pld@R{1}{1}
则将省略符号前的因数。
\documentclass{article}
\usepackage{polynom}
\makeatletter
\let\pldx@saved@PrintRational\pld@PrintRational
\renewcommand*{\pld@PrintRational}[2]{%
\def\pldx@do{\pldx@PrintRational{#1}{#2}}%
\futurelet\pldx@token\pldx@do
}
\newcommand*{\pldx@PrintRational}[2]{%
\let\pldx@do\@firstofone
\ifx\pldx@token\pld@S
\def\pldx@a{#1}%
\def\pldx@b{#2}%
\ifx\pldx@a\pldx@b
\let\pldx@do\@gobble
\fi
\fi
\pldx@do{%
\pldx@saved@PrintRational{#1}{#2}%
}%
}
\makeatother
\begin{document}
\polylongdiv{x^3-x^2+d}{x-2}%
\polylongdiv{x^3-x^2-3+d}{x-2}%
% David Carlisle's test cases:
\polylongdiv{x^3-x^2+1}{x-2}
\polylongdiv{1+d}{1}
\end{document}