Printing out LaTeX Variables
Asked Answered
N

4

19

I am using a LaTeX class file which sets various parameters such as margins, line spacing, ... according to the parameters passed to it. For some reason, the end result does not look right. Some margins are not properly set. I'd like to print out the values of various variables that LaTeX have computed along the way to see where the problem is. For instance, I'd like to know what the value of \oddsidemargin is in a certain line of code. Is there a way to ask LaTeX to print out such information?

Noonan answered 22/7, 2009 at 22:3 Comment(0)
S
13

For debugging page layout, Peter Wilson's layouts package is the way to go. Here's an example for visualising the page design and seeing the dimensions used for it:

\documentclass{article}
\usepackage{layouts}
\begin{document}
\drawmarginparstrue
\currentpage
\pagedesign
\end{document} 

There are many features to fine-tune the information returned by the package. It also provides the \prntlen command to print the size of a length in case you don't need so much information.

Sterilize answered 23/7, 2009 at 5:57 Comment(2)
And, usefully, I see that you are the maintainer. How does \printlen differ from the \printlength macro dmckee linked to?Gyn
If not identical, they're essentially the same. The layouts package does a whole lot more, however; printlen.sty is just the little bit of code to pretty print lengths.Sterilize
D
32

You can insert the value of a variable with \the:

\the\oddsidemargin
Dusty answered 22/7, 2009 at 23:25 Comment(2)
Does this work with @ variables also? I'm trying to print out \@currenvir.Glaser
You need to use makeatletter/makeatother for @-variables.Dusty
S
13

For debugging page layout, Peter Wilson's layouts package is the way to go. Here's an example for visualising the page design and seeing the dimensions used for it:

\documentclass{article}
\usepackage{layouts}
\begin{document}
\drawmarginparstrue
\currentpage
\pagedesign
\end{document} 

There are many features to fine-tune the information returned by the package. It also provides the \prntlen command to print the size of a length in case you don't need so much information.

Sterilize answered 23/7, 2009 at 5:57 Comment(2)
And, usefully, I see that you are the maintainer. How does \printlen differ from the \printlength macro dmckee linked to?Gyn
If not identical, they're essentially the same. The layouts package does a whole lot more, however; printlen.sty is just the little bit of code to pretty print lengths.Sterilize
R
5

CTAN says: printlen which allows you to specify the output units.

Rugger answered 22/7, 2009 at 23:23 Comment(0)
C
4

Try also this:

\usepackage[verbose]{geometry}
Chengteh answered 30/7, 2009 at 12:25 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.