Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Similar questions have been asked, but none have answered my particular problem.

I am trying to declare in a report a new environment which would be similar to the abstract environment. I have looked at the code in report.cls and found the definition for the abstract environment:

\if@titlepage
  \newenvironment{abstract}{%
      \titlepage
      \null\vfil
      \@beginparpenalty\@lowpenalty
      \begin{center}%
        \bfseries \abstractname
        \@endparpenalty\@M
      \end{center}}%
     {\par\vfil\null\endtitlepage}
\else
  \newenvironment{abstract}{%
      \if@twocolumn
        \section*{\abstractname}%
      \else
        \small
        \begin{center}%
          {\bfseries \abstractname\vspace{-.5em}\vspace{\z@}}%
        \end{center}%
        \quotation
      \fi}
      {\if@twocolumn\else\endquotation\fi}
\fi

In my document I have declared the test environment in the same fashion, and used it as I would use abstract:

\documentclass[]{report}

\newcommand\testname{Test}

\newenvironment{test}{%
    \small
    \begin{center}%
        {\bfseries \testname\vspace{-.5em}\vspace{\z@}}%
    \end{center}%
    \quotation}
    {\endquotation}

\begin{document}

\begin{test}
Test
\end{test}

\end{document}

This results in the following error:

./test.tex:15: Undefined control sequence. [\begin{test}]
./test.tex:15: Missing number, treated as zero. [\begin{test}]
If you can't figure out why I needed to see a number,:15: Illegal unit of measure . [\begin{test}]

I understand the problem comes from the \z@ but I understand neither why nor how to fix this.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

Since the definition involves the @ character (with category code 12), you need to enclose it between \makeatletter, \makeatother to change its category code to 11 during the definition, and back to 12 after the definition:

\documentclass[]{report}

\newcommand\testname{Test}

\makeatletter
\newenvironment{test}{%
    \small
    \begin{center}%
        {\bfseries \testname\vspace{-.5em}\vspace{\z@}}%
    \end{center}%
    \quotation}
    {\endquotation}
\makeatother

\begin{document}

\begin{test}
Test
\end{test}

\end{document}

If insetad of \z@ you use 0pt, you don't need \makeatletter, \makeatother:

\documentclass[]{report}

\newcommand\testname{Test}

\newenvironment{test}{%
    \small
    \begin{center}%
        {\bfseries \testname\vspace{-.5em}\vspace{0pt}}%
    \end{center}%
    \quotation}
    {\endquotation}

\begin{document}

\begin{test}
Test
\end{test}

\end{document}

However, a simpler approach would be to say:

\documentclass[]{report}

\newcommand\testname{Test}
\newenvironment{test}
  {\renewcommand\abstractname{\testname}\begin{abstract}}
  {\end{abstract}}

\begin{document}

\begin{test}
Test
\end{test}

\end{document}
share|improve this answer
    
Thanks for your answer. The first code sample resolves the compilation error, and the last code sample answers my initial question. Could you please nonetheless explain why when using \makeatletter (or 0pt) the layout of the defined test environment is actually not the same as the abstract environment (it is not vertically centred on the page)? –  sirdharma Oct 21 '12 at 0:24
    
@sirdharma that's because you are not using the \null\vfil and \vfil\null commands of the original definition; if you want your environment to behave exactly as the original one (excepting the name), the simpler option is to do something like my last example shows. –  Gonzalo Medina Oct 21 '12 at 0:28
    
I have already applied your last example and it solves my problem. I would just like to understand where do the \null\vfil and \vfil\null commands come from in that case? They only seem to be used when the abstract is within the title page if you look at the code I extracted from report.cls. –  sirdharma Oct 21 '12 at 0:32
3  
@sirdharma they are used if the boolean switch \if@titlepage is true, and in report.cls you find \@titlepagetrue so, by default, the boolean switch is true and the first definition applies. –  Gonzalo Medina Oct 21 '12 at 0:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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