
我正在實現非標準運算符,方法是使用pict2e
套件將它們繪製為圖片,然後縮放它們以適應各種數學模式。我將圖片的參數儲存在外部巨集中,並在picture
。
這是一個最小的例子:
\documentclass{article}
\usepackage{pict2e}
\def\num{3}
\def\decimal{3.2}
\newcommand*\testfigure{%
\begin{picture}(3,3)(0,0)
\put(0, 0){\line(0, \decimal){\num}}
\end{picture}
}
\begin{document}
\testfigure
\end{document}
然而,在 Overleaf 和我本地的 TeX Live 安裝上編譯它會引發錯誤:缺失 = 插入\ifnum
。接下來是另一個錯誤:缺少數字,視為 0。請注意,當我使用 定義\decimal
巨集時,此行為會重複\newcommand
。當數字有小數點但沒有小數部分時(例如 3. 和 3.0),也會發生這種情況。
此行為會在使用或任何其他圖片指令時重複出現\vector
,但不會重複出現。\qbezier
如果我\decimal
用十進制數字替換調用,編譯就會成功。我知道pict2e
支持實斜率論證,而不是 的互質限制picture
。我也知道它只\ifnum
作用於整數。
為什麼在這種情況下編譯會失敗,為什麼只有 with \line
?如何\line
從宏中正確給出小數斜率參數?
答案1
這是pict2e
.我給維護者發了郵件,羅爾夫積極回覆。他合併了以下更改,問題現在應該得到解決(版本 0.3c,20-08-2019)。
此巨集\pIIe@checkslopeargs
用於執行下列操作:
\renewcommand*\pIIe@checkslopeargs[3]{%
\def\@tempa{#1}\expandafter\pIIe@checkslopearg\@tempa.:{#3}%
\def\@tempa{#2}\expandafter\pIIe@checkslopearg\@tempa.:{#3}%
\ifdim #1\p@=\z@ \ifdim #2\p@=\z@ \@badlinearg \fi\fi}
它將第一個參數儲存在臨時巨集 ( \def\@tempa{#1}
) 中,然後擴展該臨時巨集並\pIIe@checkslopearg
使用它進行呼叫。然而該行
\def\@tempa{#1}\expandafter\pIIe@checkslopearg\@tempa.:{#3}
與更簡單的完全相同
\pIIe@checkslopearg#1.:{#3}
當展開時,在 中\pIIe@checkslopearg
分割,如果它隱藏在巨集中,它不會找到點,但如果您明確傳遞它,它確實可以工作。之後,一個十進制數進入測試,基本上變成,失敗並顯示。#1
.
\decimal
\ifnum
\ifnum3.2<\z@
Missing = inserted for \ifnum
事實上,參數儲存在臨時巨集和程式碼中做支持十進制數字,讓我相信這是一個錯誤。要修復它,您可以將兩者替換\def
為\edef
。我還在巨集中添加了一個缺少的空格,這會觸發不必要的擴充。
加載後將其放入序言中pict2e
:
\makeatletter
\renewcommand*\pIIe@checkslopeargs[3]{%
% V \edef instead of \def
\edef\@tempa{#1}\expandafter\pIIe@checkslopearg\@tempa.:{#3}%
\edef\@tempa{#2}\expandafter\pIIe@checkslopearg\@tempa.:{#3}%
\ifdim #1\p@=\z@ \ifdim #2\p@=\z@ \@badlinearg \fi\fi}
\def\pIIe@checkslopearg #1.#2:#3{%
\def\@tempa{#1}%
\ifx\@tempa\empty\def\@tempa{0}\fi
\ifx\@tempa\space\def\@tempa{0}\fi% V added space
\ifnum\ifnum\@tempa<\z@-\fi\@tempa>#3 \@badlinearg \fi}
\makeatother