1

I have the following code setting as main font GFSArtemisia containing just two paragraphs of text with some empty spaces to be completed from students. I noticed that if I use as main font some fonts other than the default font of LaTeX as GFSArtemisia, Comic Sans, Segoe Script, STIX Two Text and probably other than I haven't checked, the line breaks does not work properly as you can see in the picture below. How can be fixed than manually placing \linebreak at the end of each line that have not the right line break? Please note: If you comment the 7th line of the code below: \setmainfont{GFSArtemisia}\setsansfont{FiraSans}\setmonofont{Consolas} then the result has no problems. Here is the MWE:

% !TeX program = lualatex
\documentclass[12pt]{article}
\usepackage[a4paper, total={180mm,257mm},left=15mm,top=20mm]{geometry}
\usepackage{setspace}
\usepackage[no-math]{fontspec}
\defaultfontfeatures{Scale=MatchLowercase, Script=Greek}\defaultfontfeatures[\rmfamily]{Scale=1.1}
\setmainfont{GFSArtemisia}\setsansfont{FiraSans}\setmonofont{Consolas}
\newcommand\dotfillin[1][4cm]{\makebox[#1]{\dotfill}}


\begin{document}
    \doublespacing
    
    \noindent This is a text \dotfillin[5cm] containing some empty \dotfillin[5cm] spaces to be completed from \dotfillin[5cm] students, but if set main font to some other fonts like \dotfillin[5cm] STIX Two Tesxt, Comic Sans, Segoe Script, GFS Artemisia and others \dotfillin[5cm] the linebreaks \dotfillin[5cm] does not work properly \dotfillin[5cm]. How can be fixed \dotfillin[5cm]?
    
    \noindent Lorem ipsum dolor sit amet, consectetur adipiscing  \dotfillin[5cm] elit, sed do eiusmod tempor incididunt ut labore et \dotfillin[5cm] dolore magna aliqua. Ut enim ad minim \dotfillin[5cm] veniam, quis nostrud \dotfillin[5cm] exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit \dotfillin[5cm] in voluptate velit esse cillum dolore eu \dotfillin[5cm] fugiat nulla pariatur. \dotfillin[5cm] excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia \dotfillin[5cm] deserunt mollit anim id est laborum.

\end{document}

enter image description here

5
  • 1
    why should there be linebreaks? your dots are in a box. Commented Feb 25, 2023 at 17:26
  • Why the box is not send as a whole in the next line? And why the same problem does not occur with the default font of Latex and some other fonts as GFSNeohellenic?
    – miltos
    Commented Feb 25, 2023 at 17:29
  • 2
    Different fonts, different linebreaks. Beside this you are scaling the font and so there is less on the line. Use \raggedright. (And I wouldn't use Script=Greek for a latin text.) Commented Feb 25, 2023 at 17:37
  • @Ulrike Fischer: You have right about Script=Greek, I forgot it there when I was writing the MWE, but make no difference if I remove it. Scaling sometimes is necessary, so I cannot avoid it. I will follow your advice to use \raggedright.
    – miltos
    Commented Feb 25, 2023 at 17:42
  • @Ulrike Fischer: Unfortunately, \raggedright does not produce the desired result.
    – miltos
    Commented Feb 25, 2023 at 18:00

1 Answer 1

1

Adding \sloppy resolves all overflow boxes in this example.

a

% !TeX program = lualatex
\documentclass[12pt]{article}
\usepackage[a4paper, total={180mm,257mm},left=15mm,top=20mm,showframe]{geometry}
\usepackage{setspace}
\usepackage[no-math]{fontspec}
\defaultfontfeatures{Scale=MatchLowercase}\defaultfontfeatures[\rmfamily]{Scale=1.1}
\setmainfont{GFSArtemisia}\setsansfont{FiraSans}\setmonofont{Consolas}
\newcommand\dotfillin[1][4cm]{\makebox[#1]{\dotfill}}
    
\begin{document}
    \sloppy % <<<<<<<<<<<<<<<<
    
    \doublespacing
    
    \noindent This is a text \dotfillin[5cm] containing some empty \dotfillin[5cm] spaces to be completed from \dotfillin[5cm] students, but if set main font to some other fonts like \dotfillin[5cm] STIX Two Tesxt, Comic Sans, Segoe Script, GFS Artemisia and others \dotfillin[5cm] the linebreaks \dotfillin[5cm] does not work properly \dotfillin[5cm]. How can be fixed \dotfillin[5cm]?
    
    \noindent Lorem ipsum dolor sit amet, consectetur adipiscing  \dotfillin[5cm] elit, sed do eiusmod tempor incididunt ut labore et \dotfillin[5cm] dolore magna aliqua. Ut enim ad minim \dotfillin[5cm] veniam, quis nostrud \dotfillin[5cm] exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit \dotfillin[5cm] in voluptate velit esse cillum dolore eu \dotfillin[5cm] fugiat nulla pariatur. \dotfillin[5cm] excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia \dotfillin[5cm] deserunt mollit anim id est laborum.
    
\end{document}

A similar result is generated with \setlength{\emergencystretch}{2em}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .