Paragraph with a given aspect ratio?












5














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}









share|improve this question
























  • Do you mean ratio?
    – azetina
    Jan 5 '14 at 22:26






  • 1




    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












  • Related: tex.stackexchange.com/questions/123614/…
    – Steven B. Segletes
    Jan 6 '14 at 13:34


















5














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}









share|improve this question
























  • Do you mean ratio?
    – azetina
    Jan 5 '14 at 22:26






  • 1




    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












  • Related: tex.stackexchange.com/questions/123614/…
    – Steven B. Segletes
    Jan 6 '14 at 13:34
















5












5








5







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}









share|improve this question















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}






tikz-pgf line-breaking paragraphs varwidth






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 5 '14 at 23:09









David Carlisle

482k3811141851




482k3811141851










asked Jan 5 '14 at 22:23









Yossi Gil

7,123341102




7,123341102












  • Do you mean ratio?
    – azetina
    Jan 5 '14 at 22:26






  • 1




    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












  • Related: tex.stackexchange.com/questions/123614/…
    – Steven B. Segletes
    Jan 6 '14 at 13:34




















  • Do you mean ratio?
    – azetina
    Jan 5 '14 at 22:26






  • 1




    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












  • Related: tex.stackexchange.com/questions/123614/…
    – Steven B. Segletes
    Jan 6 '14 at 13:34


















Do you mean ratio?
– azetina
Jan 5 '14 at 22:26




Do you mean ratio?
– azetina
Jan 5 '14 at 22:26




1




1




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






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






shapepar package (from same author as varwidth)
– David Carlisle
Jan 5 '14 at 23:08














Related: tex.stackexchange.com/questions/123614/…
– Steven B. Segletes
Jan 6 '14 at 13:34






Related: tex.stackexchange.com/questions/123614/…
– Steven B. Segletes
Jan 6 '14 at 13:34












1 Answer
1






active

oldest

votes


















7














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
strutBODYstrut
}
% 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}


enter image description here



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






share|improve this answer























  • Many thanks! It looks great.
    – Yossi Gil
    Jan 6 '14 at 4:46











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f152602%2fparagraph-with-a-given-aspect-ratio%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









7














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
strutBODYstrut
}
% 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}


enter image description here



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






share|improve this answer























  • Many thanks! It looks great.
    – Yossi Gil
    Jan 6 '14 at 4:46
















7














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
strutBODYstrut
}
% 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}


enter image description here



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






share|improve this answer























  • Many thanks! It looks great.
    – Yossi Gil
    Jan 6 '14 at 4:46














7












7








7






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
strutBODYstrut
}
% 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}


enter image description here



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






share|improve this answer














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
strutBODYstrut
}
% 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}


enter image description here



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







share|improve this answer














share|improve this answer



share|improve this answer








edited 50 mins ago

























answered Jan 5 '14 at 23:31









egreg

708k8618813163




708k8618813163












  • Many thanks! It looks great.
    – Yossi Gil
    Jan 6 '14 at 4:46


















  • Many thanks! It looks great.
    – Yossi Gil
    Jan 6 '14 at 4:46
















Many thanks! It looks great.
– Yossi Gil
Jan 6 '14 at 4:46




Many thanks! It looks great.
– Yossi Gil
Jan 6 '14 at 4:46


















draft saved

draft discarded




















































Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f152602%2fparagraph-with-a-given-aspect-ratio%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Accessing regular linux commands in Huawei's Dopra Linux

Can't connect RFCOMM socket: Host is down

Kernel panic - not syncing: Fatal Exception in Interrupt