2

I want to have the theorem names appear in the margin. I've tried using the margin notes to do this but I was unable to do so.

Here is a picture of what I am trying to do. The top line is how the theorem environment works by default, below is what I would like. enter image description here

Here is I what i tried to do, altough I must admit I don't have a good understanding of how to do something like this

 \newenivorment{margintheorem}[#2]{
 \begin{theorem}[\marginnote{#2}]

 \end{theorem}
 }
7
  • 1
    Welcome to TeX SX! Could you post a compilable code of what you've tried?
    – Bernard
    Commented Nov 29, 2019 at 20:13
  • by compilable do you mean to include all the packages and the preable I've used?
    – Emily
    Commented Nov 29, 2019 at 20:26
  • Not all, but the relevant packages and a preamble, so I can compile immediately to try to see what happens.
    – Bernard
    Commented Nov 29, 2019 at 20:28
  • \newenivorment{margintheorem}[#2]{ is wrong. It should be something like \newenivorment{margintheorem}[2]{ or so.
    – user194703
    Commented Nov 29, 2019 at 21:11
  • 1
    @Schrödinger'scat: Oh, now I understand (perhaps): perhaps you interpreted my comment as a remark addressed to you! No, my advice to post only actual code was meant for the OP!
    – GuM
    Commented Nov 29, 2019 at 23:04

2 Answers 2

5

You can define indirectly the theorem environment:

\documentclass{article}
\usepackage{amsthm,marginnote,xparse}

\newtheorem{theoreminner}{Theorem}
\NewDocumentEnvironment{theorem}{o}
 {\theoreminner\IfValueT{#1}{\marginnote{\normalfont\footnotesize#1}}}
 {\endtheoreminner}

\reversemarginpar

\begin{document}

\begin{theorem}
This theorem has no attribution.
\end{theorem}

\begin{theorem}[theorem name]
This theorem has a name.
\end{theorem}

\end{document}

enter image description here

1

Your question lacks some important details, and in particular you do not specify whether or not you are using a particular package to define your “theorem-like” environments. I’ll assume that you are using amsthm.

The following solution hacks directly into amsthm's definition of the \@begintheorem command, and so applies automatically to all kinds of “theorem-like” environment (propositions, lemmas, definitions…). It is based on the use of the \marginpar command from the LaTeX kernel: this makes things a bit more complicated, because this command must be issued “in outer paragraph mode”. Indeed, I wrote the code exactly with the intent of showing that a solution based on the original \marginpar command was possible.

% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly 
                                 % declare the paper format.

\usepackage[T1]{fontenc}         % Not always necessary, but recommended.
% End of standard header.  What follows pertains to the problem at hand.

% \usepackage{amsmath} % not essential, but you probably want it too
\usepackage{amsthm}
\usepackage{etoolbox} % for "\patchcmd"/"\pretocmd"



%%%%%%%% BEGIN WIZARDRY %%%%%%%%

\makeatletter

\wlog{****************************************}
\patchcmd{\@begintheorem}{% search for:
    \@ifempty{#3}{\let\thmnote\@gobble}{\let\thmnote\@iden}%
    \thm@swap\swappedhead\thmhead{#1}{#2}{#3}%
}{% replace with:
    \let\thmnote\@gobble
    \thm@swap\swappedhead\thmhead{#1}{#2}{}%
}{% execute if succeeded:
    \wlog{>>> 1st patch succeeded.}
}{% execute if failed:
    \wlog{>>> 1st patch FAILED!}
}
\pretocmd{\@begintheorem}{% prepended code:
    \@ifnotempty{#3}{\def\@thm@marginal@note@text{#3}}%
}{% execute if succeeded:
    \wlog{>>> 2nd patch succeeded.}
}{% execute if failed:
    \wlog{>>> 2nd patch FAILED!}
}
\wlog{****************************************}

\newcommand*\@thm@marginal@note@text{}
\newcommand*\@thm@marginal@note@helper{%
    \begingroup \setbox\z@ \lastbox \endgroup
    \marginnote{\@thm@marginal@note@text}%
}
\dth@everypar = \expandafter {%
    \expandafter \@thm@marginal@note@helper
    \the \dth@everypar
}

\makeatother

%%%%%%%%  END WIZARDRY  %%%%%%%%



\newcommand*{\marginnote}[1]{%
    \marginpar
        [\footnotesize\raggedleft  #1]%
        {\footnotesize\raggedright #1}%
}
\reversemarginpar % ?

\newtheorem{theorem}{Theorem}
\newtheorem{lemma}  {Lemma}
\theoremstyle{definition}
\newtheorem{defin}{Definition}



\begin{document}

This text comes before the first definition.

\begin{defin}[Important definition]
    A definition is \textbf{important} if and only if it is not
    unimportant.
\end{defin}

And, of course:

\begin{defin}
    An \textbf{unimportant} definition is one that is not important.
\end{defin}

Now a theorem:

\begin{theorem}[Important Theorem]
    All theorems are important, but some theorems are more important 
    than others.
\end{theorem}

The proof rests on the following

\begin{lemma}[Important lemma]
    Not all theorems (or lemmas) are equally important.
\end{lemma}

An unimportant theorem:

\begin{theorem}
    Blah blah blah\ldots
\end{theorem}

And an unimportant lemma:

\begin{lemma}
    Blah blah blah\ldots
\end{lemma}

Here is a little more text.

\end{document}

Note the old-fashioned, “vintage” code, and its use of \expandafter… ;-)

The output:

Output of the code

You must log in to answer this question.

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