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;m trying to utilise this method for putting a box around text: http://tex.stackexchange.com/a/20326/17049

But it doesn't work with large text...

MWE:

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
    \pgfmathwidth{\Large "Text"}
\end{tikzpicture}
\end{document}

Causes:

! TeX capacity exceeded, sorry [input stack size=5000].
\@nomath ...e \@font@warning {Command \noexpand #1
                                                  invalid in math mode}\fi
l.6     \pgfmathwidth{\Large "Text"}
share|improve this question
3  
From the PGF Manual: "It is important to remember that any expression is expanded with \edef before being parsed, so any macros (e.g., font commands like \tt or \Huge) will need to be \protected" (e.g., \noexpand\Huge is usually sufficient)." –  Kevin C Jan 23 at 17:55
2  
@KevinC With \pgfmathwidth{"\noexpand\Large Text"}, \pgfmathresult is set to 0pt. On the other hand, \pgfmathwidth{\noexpand\Large "Text"} gives errors. –  egreg Jan 23 at 18:01
    
@egreg: That's strange... I get the correct measures with your first syntax. See my answer below. –  Kevin C Jan 23 at 18:04

1 Answer 1

up vote 4 down vote accepted

From the PGF Manual:

It is important to remember that any expression is expanded with \edef before being parsed, so any macros (e.g., font commands like \tt or \Huge) will need to be "protected" (e.g., \noexpand\Huge is usually sufficient)."

MWE

\documentclass{article}
\usepackage{tikz}
\setlength\parskip{20pt}
\begin{document}
Width of text: \pgfmathwidth{"Text"}\pgfmathresult

Width of {\Large Text}: \pgfmathwidth{"\noexpand\Large Text"}\pgfmathresult

Width of {\Huge Text}: \pgfmathwidth{"\noexpand\Huge Text"}\pgfmathresult
\end{document}

Output

enter image description here

share|improve this answer
    
Did you try it inside a tikzpicture environment? –  egreg Jan 23 at 18:03
    
@egreg: You're right, \pgfmathwidth{"\noexpand\Large Text"} doesn't work inside a tikzpicture environment, except when issued in a \node. Could this be a bug? I'm still using PGF 2.10 though. –  Kevin C Jan 23 at 18:14
1  
you need two more \noexpand to make it work. there must be a duplicate for this somewhere –  percusse Jan 23 at 18:25
    
@percusse: \pgfmathwidth{"\noexpand\noexpand\noexpand\Large Text"} gives a result of 20.00003, which is the same as \pgfmathwidth{"Text"}. But this is still incorrect :( –  Kevin C Jan 23 at 18:34

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.