5

I've got a document which should not be longer than one page (in this case a resume). At present: whenever I make a change, I have to compile (not sure if this is the right terminology, I'm fairly new to tex) the document, and then open it and check if it's longer than a page. I would love a solution which simply prevents it from compiling if it is longer than a page.

Here's my preamble:

\documentclass[12pt, letterpaper]{article}

\usepackage[letterpaper,margin=0.75in]{geometry}
\usepackage[compact]{titlesec}

\titleformat*{\subsection}{\large\bfseries}
\titlespacing{\section}{0pt}{\parskip}{-\parskip}
\titlespacing{\subsection}{0pt}{\parskip}{-\parskip}

\renewcommand{\familydefault}{\sfdefault}
\renewcommand\labelitemi{$\cdot$}
\pagestyle
4
  • I see the effect you're aiming for, but having the whole thing typeset is often helpful in finding the cause of the overrun. Or at least that's what I've found. – Chris H Sep 4 '17 at 17:13
  • Good point. Is there some equivalent to compiler warnings? – Jones Sep 4 '17 at 17:14
  • There are warnings. Whether you're shown them automatically depends on how you compile. I see them because I compile from the command line. Often when you push a button in an IDE they're not displayed by default. – Chris H Sep 4 '17 at 17:26
  • The number of pages should be in the output log even without opening the output file: Typeset pages show as "[1][2]" and there should also be a summary line stating the numbre of pages output. – Hagen von Eitzen Sep 4 '17 at 21:25
5

You will always need to compile the document, because the number of pages will not be known without. But you can throw an error, if the you have more than one pages:

\documentclass{article}

\usepackage{scrlfile}% Provides \AfterReadingMainAux
\usepackage{lipsum}

\AfterReadingMainAux{%
  \ifnum\value{page}>2
    \GenericError{}{File \jobname.tex Error: More than one page}{}{}%
  \fi
}
\begin{document}
\lipsum[1-5]
%\lipsum[6]
\end{document}

If you remove the % before \lipsum[6] you will get an error:

./test.tex:14: File test.tex Error: More than one page.


Type  H <return>  for immediate help.
 ...                                              

l.14 \end{document}

If you prefer a warning:

\documentclass{article}

\usepackage{scrlfile}
\usepackage{lipsum}

\AfterReadingMainAux{%
  \ifnum\value{page}>2
    \GenericWarning{}{File \jobname.tex Warning: Document has
      \the\numexpr\value{page}-1\relax\space pages}{}%
  \fi
}
\begin{document}
\lipsum[1-5]
\lipsum[6]
\end{document}

Will result in the warning:

File test.tex Warning: Document has 2 pages on input line 15.

And if you want information where the new page starts:

\documentclass{article}

\usepackage{atbegshi}
\usepackage{lipsum}

\AtBeginShipout{%
  \ifnum\value{page}>1
    \GenericError{}{File \jobname.tex Warning: Starting page \thepage}{}{}%
  \fi
}
\begin{document}
\lipsum
\lipsum
\lipsum
\lipsum
\lipsum
\end{document}

But note: Because of the asynchronous output of TeX you won't get information about the word, that causes the second, third etc. page. You will only get information, which command or paragraph result in a new page break. So the line number of the message is only an approach not the exact position.

4

Hope this helps:

\documentclass{article}

\usepackage{lipsum}

%http://latex.org/forum/viewtopic.php?t=21514
\newcommand{\bailout}{%
\ifnum\value{page}>1 
%\undefinedcommand % uncomment to abort
\typeout{more than one page}
\fi
}

\begin{document}

\lipsum[1-6]

\bailout
\end{document}
1
  • Putting the command at the end would also be useful if you wanted to display a warning and have it appear last and most obvious – Chris H Sep 4 '17 at 17:27

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.