정리 환경을 위한 매크로

정리 환경을 위한 매크로

타자치기가 고통스럽다

\begin{theorem}
...
\end{theorem}

\begin{proof}
...
\end{proof}

수업시간에 문서를 실시간으로 문자로 보낼 때.

내가 선언할 때

\newcommmand{\theorem}[2]{\begin{theorem} {#1} \begin{proof} {#2} \end{proof} \end{theorem}}

나는 그것이 \theorem이미 정의되어 있다는 것을 알았습니다.

내가 시도하면

\renewcommmand{\theorem}[2]{\begin{theorem} {#1} \begin{proof} {#2} \end{proof} \end{theorem}}

치명적인 오류가 발생합니다.

시작, 끝, 증명이라는 단어를 여러 번 입력하지 않아도 되는 방법이 있나요? 이것은 수업 중에 실시간으로 메모를 보낼 때 중요합니다.

답변1

당신은 그것을 할 수 있습니다

\newcommand{\thmpr}[2]{%
  \begin{theorem}#1\end{theorem}%
  \begin{proof}#2\end{proof}%
}

하지만 이것이 훨씬 더 나쁘다는 점을 경고합니다. 서로 매우 멀리 떨어져 있을 수 있는 교정기를 추적해야 합니다.

수업 메모를 작성하는 경우 태그를 지정하는 것이 훨씬 쉽습니다.

THEOREM\\
Whatever the guy at the blackboard is saying

PROOF\\
Something even more mysterious that I'll go through later

그러면 재료를 수정할 때 필수 항목 \begin과 태그를 쉽게 배치할 수 있습니다 .\end


문제는 내부 목적으로 매크로를 \newtheorem{theorem}{Theorem}정의한다는 것입니다. \theorem그래서 LaTeX는 이를 거부합니다 \newcommand{\theorem}[2]{...}. 하지만 함께

\renewcommand{\theorem}[2]{\begin{theorem}...}

당신은 \theorem그 자체로 정의하고 있으며 이로 인해 무한 루프가 발생합니다.

답변2

정의의 문제는 \begin{theorem}암시적 으로 \theorem. 이것이 첫 번째 시도에서 '이미 정의된' 오류가 발생하는 이유입니다. (결국 환경은 실제로 바로 그 매크로입니다.) 두 번째 시도에서는 재정의하려는 매크로 내부에서 매크로를 호출합니다. 그래서 무한루프에 빠지게 됩니다. \theorem다음과 같이 말하여 버전을 저장해 보세요.

\let\oldtheorem\theorem

두 번째 시도는 기본적으로 작동합니다.

\documentclass{article}
\usepackage{amsthm}

\newtheorem{theorem}{Theorem}
\let\oldtheorem\theorem
\let\endoldtheorem\endtheorem
\renewcommand\theorem[2]{\begin{oldtheorem}#1\end{oldtheorem}\begin{proof}#2\end{proof}}

\begin{document}
\theorem{a theorem}{with proof}
\end{document}

또한 환경은 일반적으로 인수 주위에 그룹화되어 proof내부에 중첩되지 않습니다. 즉 ' '는 필요하지 않습니다.theorem{#1}

관련 정보