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.

I compile small latex math snippets using the standalone document class. I rasterize the resulting PDF to a PNG image using ImageMagick and finally include these images in some HTML document. However, for technical reasons of this procedure, I want to ensure a specific height of the document above + below the baseline, let's say the letter "Q" should always fit vertically, even if the document only contains one single "a".

I thought about including a phantom letter, but this also introduces additional whitespace in the horizontal dimension. Is there an easy way to tell standalone (or a special environment) to at least include a specific height above + below the baseline of the text? Is there some phantom-similar thing which enlarges the bounding box but doesn't occupy space by itself? I also thought abut a tikz image which doesn't draw anything but specify a bounding box. However, including the tikz package for this reason only will make compilation very slow since I have to compile dozens of latex snippets.

I use lualatex (but only because of the easy integration of true type fonts) and currently I compile the latex snippets using the following document template (the ... is replaced with the latex snipped to be rendered):

\documentclass{standalone}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage{arev}
\usepackage{amsmath}
\begin{document}
$...$
\end{document}

(If this is not possible, I'll just use a phantom text to specify my minimum vertical bounding box + auto-crop the rasterized image horizontally.)

share|improve this question
1  
There is \vphantom that only uses the vertical dimensions. –  egreg Nov 27 '12 at 21:09
    
Nice! This solves the problem. Thank you, @egreg –  leemes Nov 27 '12 at 21:16

1 Answer 1

up vote 8 down vote accepted

There are many ways to do it; the simplest is perhaps to use \vphantom{Q} instead of \phantom{Q}, that uses only the vertical dimensions of "Q".

Another method is to use a strut:

\begin{document}
\strut a
\end{document}

The command \strut produces an invisible object such that its height and depth sum up to the baseline skip. Here are three examples: the first is with

\begin{document}
Q
\end{document}

the second with

\begin{document}
\vphantom{Q}a
\end{document}

and the third is with the strut. I've added the frames to better see the result.

enter image description here

share|improve this answer
    
Thank you very much, especially for the second solution, which is exactly what I had in mind. –  leemes Nov 27 '12 at 21:40
    
I'm still struggling: I want exactly 2\baselineskip above and below the baseline of the text (so I can exactly measure where the baseline is in the rasterized image plus measure the line spacing). The "Q" only was a start to solve the problem. Like with the "Q", the strut will not allow me to measure the baseline exactly. Can you please help me again? I hope you understand the problem. ;) Thanks! –  leemes Nov 28 '12 at 21:55
2  
@leemes Try \vrule width 0pt height 2\baselineskip depth 2\baselineskip in place of \strut –  egreg Nov 28 '12 at 21:57
    
Ok this was fast. And it works like a charm, like expected ;) Thank you so much! –  leemes Nov 28 '12 at 21:58

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.