我正在嘗試編寫一個命令來縮短用於編寫證明的命令。目前,我曾經使用
\newenvironment{proof}%
{\textbf{Proof:}}%
{\begin{flushright} $\blacksquare$ \end{flushright}}
現在我厭倦了\begin{proof}
一直寫,所以我想改用\pf{ ...content... }
or \pf[ ...content... ]
。
我嘗試做
\def\pf[#2\]{\begin{proof} #2 \end{proof}}
它不喜歡那樣。我應該要提到我已經有了
\def\[#1\]{\begin{align}#1\end{align}}
,這就是align
為什麼我沒有將其用於proof
。
答案1
我非常強烈推薦不是做這個。但是,align
如果您必須這樣做,它可能不會像您所做的那麼糟糕:
\documentclass{article}
\usepackage{xparse,amssymb}
\NewDocumentCommand \pf { +r[] } {%
\noindent\textbf{Proof:}
#1\hspace*{\fill}\nolinebreak$\blacksquare$}
\begin{document}
\pf[
Alice saw Nobody on the road, whereas the King did not.\\
So, Alice has sharper eyes than the King and Nobody is travelling on the road.]
\pf[
Alice saw Nobody on the road, whereas the King did not.\\
Hence, Alice has sharper eyes than the King.]
\end{document}
編輯:處理換行/分頁稍好。 [但是,正如我上面所說,這確實不是一個好方法。有一些套件和環境旨在使這些東西正確,同時也保持您的程式碼易於理解! ]
答案2
我不建議這樣做,但這可行(沒有任何保證)
\documentclass{article}
\usepackage{amsmath,amssymb}
\newenvironment{proof}%
{\textbf{Proof:}}%
{\hfill$\blacksquare$}
\def\pf#1{\begin{proof} #1 \end{proof}}
\begin{document}
\pf{some proof here}
\end{document}
這個比較好
- 使用 amsthm 及其環境
proof
等。 - 使用LaTeX
\newcommand
來取代\def
前者是定義新巨集的方法,用來檢查巨集是否存在。