width = getWidthOfLatexString("{\\tiny Hello} \\LaTeX{}!");
The output dimensions would be best in inches, centimeters or a
fraction of the page width. Ideally I would also like to be able to
handle UTF8 strings as well. Does anyone know how I can accomplish
this?
Thanks,
Cameron
Write a small LaTeX file, put your string into a box:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
... other font setup stuff
\sbox0{{\tiny Hello} \LaTeX!}
\typeout{width=\the\wd0}
% end job, no need for output file
\makeatletter
\@@end
run LaTeX and analyze the .log file or screen output for the wanted
width data.
Yours sincerely
Heiko <ober...@uni-freiburg.de>
> Write a small LaTeX file, put your string into a box:
>
> \documentclass{article}
> \usepackage[utf8]{inputenc}
> \usepackage[T1]{fontenc}
> ... other font setup stuff
> \sbox0{{\tiny Hello} \LaTeX!}
> \typeout{width=\the\wd0}
> % end job, no need for output file
> \makeatletter
> \@@end
>
> run LaTeX and analyze the .log file or screen output for the wanted
> width data.
That may not always work as it may depend on the context/environment
(I've been struggling with this for the past two days:-).
For example, in the following, the width that is output is 0.0pt
inside the tikzpicture and 47.16391pt outisde the tikzpicture. It
seems difficult to make the let-LaTeX-do-the-job more robust as
Cameron's program would have to know exactly what is going on. The
fact that LaTeX/TeX can construct command sequences on the fly (using
\csname), branching, and loops, seems to make the job only more
difficult.
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\sbox0{{\tiny Hello} \LaTeX!}
\typeout{width=\the\wd0}
\end{tikzpicture}
\sbox0{{\tiny Hello} \LaTeX!}
\typeout{width=\the\wd0}
\end{document}
Regards,
Marc van Dongen
> For example, in the following, the width that is output is 0.0pt
> inside the tikzpicture and 47.16391pt outisde the tikzpicture. It
Fortunately Heiko's solution will work for me. I will be constructing
a new file for every string so I shouldn't run onto the problem that
you describe.
This is a great solution, much easier than I thought it would be.
It was pointed out already to have LaTeX acquire the necessary
information. If you deal with pure textual strings (your example
however implies things like \LaTeX{} as well) AND want to stay
within a pure C programming environment you can choose the font
in which your material is expressed, convert the metrics to something
accessible in text/list form (use tftopl) and read the width data
of your property list into an array from where to calculate the length
of your string. Two caveats: You have to take into account the ligature
data and you have to calculate scaling factors for things like \tiny.
Oliver.
--
Dr. Oliver Corff e-mail: co...@zedat.fu-berlin.de
\newdimen{\fragwidth}
\settowidth{\fragwidth}{{\\tiny Hello} \\LaTeX{}!}
///Peter