0

I want to mix boxes and characters in a paragraph. But it looks sometimes no newline inserted, a box is overfull and the following character goes outside the paper.

Here is MWE (graphics are included to mimic boxes of different sizes)

\documentclass[a4paper,12pt]{article}

\usepackage[%
includeheadfoot, headheight=15pt, headsep=14pt, footskip=25pt,
top=8mm, bottom=8mm, left=1cm, right=1cm]{geometry}

\usepackage{pgffor}
\usepackage{varwidth}
\usepackage[demo]{graphicx}

\newcommand{\layoutimgs}[1] {%
    \noindent%
    \foreach \imgh / \imgw in {#1} {%
    \includegraphics[height=\imgh,width=\imgw]{demo}%
    ;\hfill%
    }%
}

\begin{document}
\layoutimgs{{11mm}/{157mm}, {5mm}/{191mm}}
\end{document}

The output is: enter image description here

The 2nd box gets overfull and the 2nd semicolon is missing.

I expect a new line starts after the 1st semicolon.

SongHerz
  • 147
  • 1
    Add \allowbreak in front of \includegraphics. – John Kormylo Nov 14 '17 at 04:26
  • @JohnKormylo Yes, it works ! By reading https://tex.stackexchange.com/a/187526/143504 and http://ctan.math.utah.edu/ctan/tex-archive/info/texbytopic/TeXbyTopic.pdf 19.1.2 "Penalties in horizontal mode are inserted by the user (or a user macro). The only exception is the \nobreak inserted before the \parfillskip glue." 19.2 "The process of breaking" I think the best practice is adding \allowbreak in horizontal mode when a line break candidate is desired, despite the complexity of TeX line breaking algorithm. – SongHerz Nov 15 '17 at 09:50

0 Answers0