# Paragraph with a given aspect ratio?

I using tikz together with package varwidth, I find myself playing out with different values for paragraph width, so as to achieve an "optimal" aspect ratio. Ideally, I would have liked to have an environment similar to varwidth which would make a best effort attempt to produce a paragraph with a given aspect ratio.

\begin{aspectparagraph}{2.5}
some text, which would automatically be formatted with
different widths, so as to find the width which is closest
to (in this case) 2.5. This could be approximated by computing the total
text natural'' length, and then computing an approximate width based on the
line height.
\end{aspectparagraph}

• Do you mean ratio? – azetina Jan 5 '14 at 22:26
• I'm not familiar with any such environment named aspectparagraph. Could you please provide a full MWE? And if this is a customized environment, could you explain what it's supposed to do? – A.Ellett Jan 5 '14 at 22:37
• shapepar package (from same author as varwidth) – David Carlisle Jan 5 '14 at 23:08
• – Steven B. Segletes Jan 6 '14 at 13:34

Here's an attempt: I compute the area and then with some math I set the box width.

\documentclass{article}
\usepackage{environ,expl3}

\ExplSyntaxOn

\box_new:N \l_yossi_longline_box
\box_new:N \l_yossi_final_box
\dim_new:N \l_yossi_base_dim

\NewEnviron{aspectparagraph}[1]
{
\hbox_set:Nn \l_yossi_longline_box { \BODY }
\dim_set:Nn \l_yossi_base_dim
{
\fp_to_dim:n {
sqrt (
\dim_to_fp:n { \box_wd:N \l_yossi_longline_box } *
\dim_to_fp:n { \baselineskip } * #1
)
}
}
\vbox_set:Nn \l_yossi_final_box
{
\hsize = \l_yossi_base_dim
\emergencystretch = \hsize
\hyphenpenalty=0
\parindent = 0pt
\strut\BODY\strut
}
% the next two lines are just for debugging
\par Height~ = ~ \dim_eval:n { \box_ht:N \l_yossi_final_box }
\par Width ~ = ~ \dim_eval:n { \box_wd:N \l_yossi_final_box } \par
\leavevmode \box_use_drop:N \l_yossi_final_box
}

\ExplSyntaxOff

\begin{document}

\begin{aspectparagraph}{2.5}
some text, which would automatically be formatted with
different widths, so as to find the width which is closest
to (in this case) 2.5. This could be approximated by computing the total
text natural'' length, and then computing an approximate width based on the
line height.
\end{aspectparagraph}

\begin{aspectparagraph}{2}
some text, which would automatically be formatted with
different widths, so as to find the width which is closest
to (in this case) 2. This could be approximated by computing the total
text natural'' length, and then computing an approximate width based on the
line height.
\end{aspectparagraph}

\begin{aspectparagraph}{1}
some text, which would automatically be formatted with
different widths, so as to find the width which is closest
to (in this case) 1. This could be approximated by computing the total
text natural'' length, and then computing an approximate width based on the
line height.
\end{aspectparagraph}

\end{document}


Maybe one can imagine doing some tentative attempts and then choose the “best” one.