0

The following code block was retrieved from this answer. It shows how to break long lines (see code and screenshot below.)

\documentclass{article}

\usepackage{lipsum}

\begin{document} \parindent0pt \makeatletter \def\scanfunction#1{#1} \let\tempa@empty \def\scan@letters#1#2{% \g@addto@macro{\tempa}{#1\hskip 0pt plus 1sp minus 1sp}% \ifx#2@empty \else \expandafter\scan@letters \fi #2}

\def\scan#1{% \scan@letters #1@empty } \scan{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa} \tempa

\lipsum[1] \end{document}

enter image description here

I noticed that when using showframe from the geometry package, one the a's exceeded the range limit (see code and image below.)

\documentclass{article}

\usepackage[showframe]{geometry}

\begin{document} \parindent0pt \makeatletter \def\scanfunction#1{#1} \let\tempa@empty \def\scan@letters#1#2{% \g@addto@macro{\tempa}{#1\hskip 0pt plus 1sp minus 1sp}% \ifx#2@empty \else \expandafter\scan@letters \fi #2}

\def\scan#1{% \scan@letters #1@empty } \scan{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa} \tempa

\end{document}

enter image description here

I solved this issue by changing 1sp to 3sp (see code and screenshot below.)

\documentclass{article}

\usepackage[showframe]{geometry}

\begin{document} \parindent0pt \makeatletter \def\scanfunction#1{#1} \let\tempa@empty \def\scan@letters#1#2{% \g@addto@macro{\tempa}{#1\hskip 0pt plus 3sp minus 3sp}% \ifx#2@empty \else \expandafter\scan@letters \fi #2}

\def\scan#1{% \scan@letters #1@empty } \scan{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa} \tempa

\end{document}

enter image description here

However, this doesn't work when increasing the font size (see code and screenshot below.). The following document was compiled using xelatex to set the font size to 60pt.

\documentclass{article}

\usepackage[showframe]{geometry}

\usepackage{lipsum}

\begin{document} \fontsize{60pt}{60pt}\selectfont \parindent0pt \makeatletter \def\scanfunction#1{#1} \let\tempa@empty \def\scan@letters#1#2{% \g@addto@macro{\tempa}{#1\hskip 0pt plus 3sp minus 3sp}% \ifx#2@empty \else \expandafter\scan@letters \fi #2}

\def\scan#1{% \scan@letters #1@empty } \scan{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa} \tempa \end{document}

enter image description here

The excess space increases as the font size increases (see code and screenshot below.) The following document was compiled using xelatex to set the font size to 100pt.

\documentclass{article}

\usepackage[showframe]{geometry}

\usepackage{lipsum}

\begin{document} \fontsize{100pt}{100pt}\selectfont \parindent0pt \makeatletter \def\scanfunction#1{#1} \let\tempa@empty \def\scan@letters#1#2{% \g@addto@macro{\tempa}{#1\hskip 0pt plus 3sp minus 3sp}% \ifx#2@empty \else \expandafter\scan@letters \fi #2}

\def\scan#1{% \scan@letters #1@empty } \scan{CCCCCCCCCCCCCC} \tempa \end{document}

enter image description here

My question is: How to break long lines without exceeding page limits for any given font size when compiling using xelatex?

rdrg109
  • 565

1 Answers1

1

As already commented in chat it's simply a choice of how much letter spacing you are prepared to accept. In the limit, if you just have two letters 1/3 \textwidth wide and you still want to justify the string you need to replace 1sp by .333\textwidth so .333\testwidth is technically the answer to your question, but it might not be the answer you want.

enter image description here

\documentclass{article}

\usepackage[showframe]{geometry}

\usepackage{lipsum}

\begin{document} \fontsize{220pt}{240pt}\selectfont \parindent0pt \makeatletter \def\scanfunction#1{#1} \let\tempa@empty \def\scan@letters#1#2{% \g@addto@macro{\tempa}{#1\hskip 0pt plus .3\textwidth minus .3\textwidth}% \ifx#2@empty \else \expandafter\scan@letters \fi #2}

\def\scan#1{% \scan@letters #1@empty } \scan{MMMMMM} \tempa \end{document}


You might prefer to use a fixed 0pt skip just to add the breakpoints and then use \raggedright so lines are left short when needed rather than being justified by arbitrarily large letter spacing.

rdrg109
  • 565
David Carlisle
  • 757,742