Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get height on a block of latex output

Tags:

latex

I am trying to determine how to get the height on a block of latex output (not the whole document, and not the code..but rather a block of output). As an example of what I am trying to accomplish: i were to have the latex code

$\sum_{i=0}^\infty \frac{1}{n}>\infty$ \newline hello world \newline hello universe

The height of the above block of text is dependent on a number of things-font, margin size, and of course what the text is, as changing any of these parameters changes how many inches that output would be, but with default formatting its output would be something like 2 inches high.

I am hoping there is a package that does this!

like image 227
georg Avatar asked May 30 '10 16:05

georg


2 Answers

Usually, the trick is to put whatever you want to measure into a box and then simply not typeset the box, but measure it:

\newdimen\height
\setbox0=\hbox{\Huge Hello, World!}
\height=\ht0 \advance\height by \dp0
The height is: \the\height
like image 117
Kilian Foth Avatar answered Nov 07 '22 22:11

Kilian Foth


I think this will work:

\newlength{\somenamehere}
\settoheight{\somenamehere}{\hbox{...}}

Where ... is your content you like to measure. And you can then use \somenamehere as the height of that content.


Example:

\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{babel}

\begin{document}
\newlength{\heightofhw}
\settoheight{\heightofhw}{\hbox{Hello World!}}
Value = \the\heightofhw
\end{document}

Will output:

Value = 6.8872pt


Note:

  • Values of lengths are stored as points, and 1 inch ≈ 72.27 pt
  • This does not require any additional packages.

Update:

Use \hbox to correctly calculate the height of a different sized environment, but it won't work with newlines :-(

like image 12
Pindatjuh Avatar answered Nov 07 '22 20:11

Pindatjuh