9

I'm trying to learn to build things from the ground-up with TeX (not LaTeX---I've used LaTeX before, so I know how easy a solution "\usepackage{amsthm}+\begin{theorem}" is) and I'm trying to build my own theorem environment that, among other things, indents on both the left and right. I know what \narrower and \leftskip (\rightskip) do. However, TeX doesn't recognize these control sequences.

\def\thm[#1]{\par {\leftskip 1in \rightskip 1in %
  \noindent {\bf Theorem.} {\it #1 \/} \newline \noindent}
\def\endthm{ } \par}

Upon compile (by the way, that's:

pdftex def.tex
* \input sandbox.tex

where def.tex contains this and sandbox.tex contains

\thm[Name of theorem] Blah blah \endthm

) I get the error saying "Undefined control sequence." So what's going on? I got the impression from my readings that these (\leftskip, &c.) are built into TeX, so it shouldn't be a package issue.

Also, that \noindent at the end of the second line doesn't work, but that's less annoying at the moment.

2
  • 2
    What makes you think that \newline is defined in Plain TeX?
    – egreg
    Nov 21 '13 at 19:05
  • @egreg, because the output skipped a line. Thanks! Nov 21 '13 at 19:16
12

\newline is not defined in Plain TeX. There are also other problems in your code: you set \leftskip and \rightskip but close the group before it can act.

\input plipsum % for mock text

\def\thm[#1]{%
  \par % get in vertical mode
  \begingroup % open a group
  \leftskip 1in \rightskip 1in % set the margins
  \noindent {\bf Theorem.} {\it #1}\par\nobreak % print the header
  \noindent\ignorespaces % print the statement
}
\def\endthm{\par\endgroup} % end the paragraph and restore the margins

\lipsum 1

\thm[Name]
\lipsum 2
\endthm

\lipsum 3

\bye

enter image description here

2
  • Excellent, thanks! I'll add the spacing before and after the environment (desirable) is obtained with \hfill before the first \par and an \hfill after the last one. Nov 22 '13 at 3:40
  • 1
    @D.Weathers This last staement is confusing. \hfill before the first \par would be horizontal space added to the previous paragraph, and would have no effect on that paragraph. Adding \hfill after the last \par would end up at the start of the following line. Surely you mean to add vertical space (maybe \bigskip) after both \pars.
    – Dan
    Nov 22 '13 at 5:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.