0

I have created some macros to simplify the my typesetting of proofs and theorems within my paper.

%the proof builder, takes 1 argument, should be a sequence of \psteps, definined next
\newcommand{\prf}[1]
{
    \begin{proof}
    \begin{align}
        #1
    \end{align}
    \end{proof}
}
% \pstep is designed for use inside the align block of a proof. takes 2 arguments {step::wff}{reference::label}
\newcommand{\pstep}[2]
{
    & #1 & \text{[#2]}
}
%the theorem builder. takes 5 arguments 
%{thm type::thm type str}{thm name::text}{reference::label}{thm statement::mathmode}{proofsteps::pstep block}
\newcommand{\theorem}[5]
{
\begin{#1}[#2]#3
    \begin{equation*}
    #4
    \end{equation*}
    \prf{#5}
\end{#1}
}

These macros work as desired. However, when I use theorem macro above, the 4th argument contains some mathmode only characters, and Overleafs syntax checker is giving a warning that the characters are not in mathmode.

        \theorem{prop}{generalized modus ponens}{\label{pred:prop:gmp}}
        {
            \vdash_1\phi\vdash_1(\forall x\phi\implies\psi)\tfs\vdash_1\psi
        }
        {
            \pstep{\phi}{hypothesis 1}\\
            \pstep{\forall x\phi}{\ref{pred:ax:gen}}\\
            \pstep{\forall x\phi\implies\psi}{hypothesis 2}\\
            \pstep{\psi}{\ref{prop:ax:mp}}
        }

interestingly it is not giving the same warning for mathmode characters inside \pstep arguments. Can anyone explain why this is? Is there a way to specify what kind of characters are allows in a macro argument so that the syntax checker knows that mathmode characters will work? Again, the macros work as intended, but I'd prefer to not have to look at these irrelevant error messages, especially if they are just cluttering actual errors.

4
  • Okay I have found some documentation referencing this problem. Link at end. It seems the code checker does not check for these kinds of cases, however I'm still confused as to why there is no error inside the \pstep macros if this is the case. overleaf.com/learn/how-to/Code_Check Commented Dec 16, 2021 at 5:40
  • I always turn of Overleaf's Code Check when using Overleaf: Overleaf is just a user interface for editing .tex files and running the latex-compiler on the .tex-files. The syntax-checker of the user interface is not really of relevance. Error-messages and warnings provided by the latex-compiler during compilation (and in case of using xetex-engines error-messages of post-processors like xdvipdfmx) are of relevance. In order to see these in Overleaf you need to inspect the .log-file created by the latex-compiler during compilation, which in the Overleaf-interface is called "raw log". Commented Dec 16, 2021 at 11:42
  • \vdash_1 would be interpreted as \vdash (a macro name), _ (math mode subscript command), 1 (the subscript, if in mathmode, as in $x_1$).
    – Cicada
    Commented Dec 16, 2021 at 12:19
  • I understand that the code checker is by no means as necessary as inspecting the error log, but as a relative noob and not a particular good typesetting, the code checker catches a lot of simple errors before the error log. For that reason I try to keep it on. Commented Dec 18, 2021 at 0:17

1 Answer 1

1

Alright I found a solution, I just switched to using the xparse package to create my custom commands. Here's the new code.

% \pstep is designed for use inside the align block of a proof. takes 2 arguments {step::wff}{reference::label}
\newcommand{\pstep}[2]
{
    & #1 & \text{[#2]}
}
%the theorem builder. takes 6 arguments {thm type::thm type str(default thm)}{thm name::text}{reference::label}{href::href}{thm statement::mathmode}{proofsteps::pstep block}

\NewDocumentCommand\theorem{O{thm} m m O{} m m}%
{
    \begin{#1}[#2]#3#4
    \begin{equation*}
    #5
    \end{equation*}
    \begin{proof}
    \begin{align}
        #6
    \end{align}
    \end{proof}
\end{#1}
}

This does not give an error with the syntax-checker AND I have much finer control of the argument options.

7
  • 1) Are you sure that you want to nest the proof-environment inside the #1-environment? If #1-environment is a theorem-like environment that for typesetting its body switches to italics after typesetting the heading in boldface, the heading of the proof-environment will be in italics also. 2) Line-endings after character-tokens like { or } yield space-tokens that in horizontal mode yield horizontal glue. In order to avoid this make sure the last thing in a line is not { or } or #5 or #6 but is {% or }% or #5% or #6%. Commented Dec 16, 2021 at 12:34
  • 3) Many people do \newtheorem{theorem}{Theorem}. Then \theorem is a macro underlying the theorem-environment. This might result in a name-clash with your \theorem-macro. Commented Dec 16, 2021 at 12:34
  • thanks for the tip! In regards to 1) as of right now my proofs and theorems have no text, only math mode equations inside of them, so I haven't had any issues with italic font weirdness, however this may change in the future. Are you suggesting I move the proof environment after then end of the theorem-like environment? I guess this would not change the layout. As for 2), can you quickly breakdown what horizontal glue means? I'm not really sure what I'm avoiding by doing that. Commented Dec 18, 2021 at 0:25
  • as for 3), I have not run into this issue as I've done \newtheorem{thm}{Theorem} Commented Dec 18, 2021 at 0:29
  • 1) If your proof-environment, e.g., prints the phrase "Proof:", that phrase will be in italics if the proof-environment is nested in a theorem-like #1-environment. 2) horizontal glue is horizontal space that can be stretched or shrunk a bit while TeX typesets the paragraph/phrase. E.g., the inter-word-space denoted in the .tex-file by a space between two words yields horizontal glue so that the horizontal space between the words can stretch or shrink when TeX distributes the text across lines in such a way that the paragraph looks best. The analogy to real glue: ... Commented Dec 18, 2021 at 0:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .