12

Is there a way to create my own error message that is given if the main font size isn't set to 11pt and then the compilation of the document begin stopped?


Update

I'm trying to write a package, and I use:

\documentclass{scrreprt}%or scrbook or scrartcl

\usepackage{classicthesis}
1
  • 1
    Isn't it easier to just set the font size, since you want to stop the compilation if it is something else? Sep 26, 2012 at 21:17

2 Answers 2

12

If you're writing a package, say foo.sty then

\AtBeginDocument{
  \if\@ptsize1\else
    \PackageError{foo}
      {Illegal font size option detected.\MessageBreak
       This is a fatal error, I'll stop the run}
      {You have specified a point size different from\MessageBreak
       the unique size this package supports, which is 11pt.\MessageBreak
       Correct your input file}
    \expandafter\@@end
  \fi}

will do.

8
  • if could help, I have updated my question. Another thing, I haven't understand why I need to ensure that the 11pt option is correctly passed to the main class. And exactly where I must put that code. Thanks.
    – Aurelius
    Sep 26, 2012 at 22:01
  • @FormlessCloud The code should be in your package. I've removed the references to a class.
    – egreg
    Sep 26, 2012 at 22:10
  • Sure, but I was referring to the deleted code: \LoadClassWithOptions...
    – Aurelius
    Sep 26, 2012 at 22:14
  • @FormlessCloud Since you're not writing a class, that code means nothing.
    – egreg
    Sep 26, 2012 at 22:18
  • Ok thanks, it was only to know something more.
    – Aurelius
    Sep 26, 2012 at 22:28
6

If you're using one of the standard document classes (article, book or report), the macro \@ptsize contains 1 if you're using 11pt:

\documentclass[12pt]{article}
\makeatletter
\AtBeginDocument{%
  \newcommand{\@ptsizetest}{1}% Equivalent to 11pt for a document class option.
  \ifx\@ptsizetest\@ptsize\relax\else
    \@latex@error
      {You need to use 11pt font size}% Error message
      {Add this as a document class option [11pt]}% Help text
  \fi%
}
\makeatother
\begin{document}
Test document
\end{document}​

This creates the error

LaTeX Error: You need to use 11pt font size.

If you're using other packages that define the font size, some more work is required.

0

You must log in to answer this question.

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