13

I need to suppress occurrences of 3 consecutive lines of text that end in hyphenated words. How to solve this?

My LaTeX Source Code is:

\documentclass{book}
\usepackage{luacode}

\begin{document}
\frenchspacing %% no extra space after punctuation marks
\begin{luacode*}
local domobject = require "luaxml-domobject"
sample = [[
<datas>
<p>The investigations of cylindrically symmetric spacetimes can be traced back as far as to 1919 when Levi-Civita (LC) discovered a class of solutions of Einstein&#x2019;s vacuums field equations, corresponding static cylindrical spacetime referring [218]. The extension of the LC spacetimes to the stationary one was independent by Lanczos in 1924 [213] and Lewis in 1932 [219]. In 1925, Beck studied a class of exact solutions and interpreted them as representing the propagation of cylindrical gravitational waves (GWs) [24]. This class of solutions was later rediscovered by Einstein and Rosen in their seminal work on the studies of the nonlinearity of GWs in 1937 [137], and in the same year van Stockum solved the problem of a rigidly rotating infinitely long cylinder of dust, and found explicitly the corresponding metric [308]. In 1957, Bonnor [43] and Weber and Wheeler [327] studied the Einstein&#x2013;Rosen waves in great details, and since then, cylindrically symmetric spacetimes have been extensively investigated with various motivations [167, 294].</p>
</datas>]]
local dom = domobject.parse(sample)
tex.sprint(dom:query_selector("p")[1]:get_text())
\end{luacode*}
\end{document}

My Output PDF is:

enter image description here

7
  • 2
    I tried an experiment: setting the paragraph in the traditional way by itself yields the same result; however, setting \doublehyphendemerits=1000000 (the default value is 10000) avoids the triple consecutive hyphens for the normal paragraph, but not for the one typeset with luacode*. Strange.
    – egreg
    Dec 23, 2020 at 10:03
  • 2
    Maybe microtype can help here.
    – Skillmon
    Dec 23, 2020 at 10:15
  • Couldn't you could simply put one of the offending words in an mbox?
    – Ingmar
    Dec 23, 2020 at 10:18
  • 1
    @MarcelKrüger Found the reason! The luacode* version doesn't like the input to be split across lines.
    – egreg
    Dec 23, 2020 at 11:11
  • 1
    What I do in such cases is to rephrase the sentence. In many cases I take the chance to find a better readable way to express what I want to say. This not only improves the look, but also the content. Don't misunderstand my comment, but there is not only one direction to go with code and TeX and so on. Dec 24, 2020 at 10:23

3 Answers 3

18

Set \doublehyphendemerits to a higher value. The default is 10000.

\documentclass{book}
\usepackage{luacode}

\begin{document}

\doublehyphendemerits=1000000

\frenchspacing%%Ignore Double Spaces

\begin{luacode*}
local domobject = require "luaxml-domobject"
sample = [[
<datas>
<p>The investigations of cylindrically symmetric spacetimes can be traced back as far as to 1919 when Levi-Civita (LC) discovered a class of solutions of Einstein&#x2019;s vacuums field equations, corresponding static cylindrical spacetime referring [218]. The extension of the LC spacetimes to the stationary one was independent by Lanczos in 1924 [213] and Lewis in 1932 [219]. In 1925, Beck studied a class of exact solutions and interpreted them as representing the propagation of cylindrical gravitational waves (GWs) [24]. This class of solutions was later rediscovered by Einstein and Rosen in their seminal work on the studies of the nonlinearity of GWs in 1937 [137], and in the same year van Stockum solved the problem of a rigidly rotating infinitely long cylinder of dust, and found explicitly the corresponding metric [308]. In 1957, Bonnor [43] and Weber and Wheeler [327] studied the Einstein&#x2013;Rosen waves in great details, and since then, cylindrically symmetric spacetimes have been extensively investigated with various motivations [167, 294].</p>
</datas>]]
local dom = domobject.parse(sample)
tex.sprint(dom:query_selector("p")[1]:get_text())
\end{luacode*}

The investigations of cylindrically symmetric spacetimes can be traced back as
 far as to 1919 when Levi-Civita (LC) discovered a class of solutions of
 Einstein’s vacuums field equations, corresponding static cylindrical
 spacetime referring [218]. The extension of the LC spacetimes to the stationary
 one was independent by Lanczos in 1924 [213] and Lewis in 1932 [219]. In 1925,
 Beck studied a class of exact solutions and interpreted them as representing the
 propagation of cylindrical gravitational waves (GWs) [24]. This class of solutions
 was later rediscovered by Einstein and Rosen in their seminal work on the studies
 of the nonlinearity of GWs in 1937 [137], and in the same year van Stockum solved
 the problem of a rigidly rotating infinitely long cylinder of dust, and found
 explicitly the corresponding metric [308]. In 1957, Bonnor [43] and Weber and
 Wheeler [327] studied the Einstein--Rosen waves in great details, and
 since then, cylindrically symmetric spacetimes have been extensively investigated
 with various motivations [167, 294].

\end{document}

enter image description here

1
  • Thanks, this helps me too....
    – MadyYuvi
    Dec 23, 2020 at 13:07
17

Using microtype I get the following:

enter image description here

\documentclass{book}
\usepackage{microtype}
\usepackage{luacode}

\begin{document}
\frenchspacing%%Ignore Double Spaces
\begin{luacode*}
local domobject = require "luaxml-domobject"
sample = [[
<datas>
<p>The investigations of cylindrically symmetric spacetimes can be traced back as far as to 1919 when Levi-Civita (LC) discovered a class of solutions of Einstein&#x2019;s vacuums field equations, corresponding static cylindrical spacetime referring [218]. The extension of the LC spacetimes to the stationary one was independent by Lanczos in 1924 [213] and Lewis in 1932 [219]. In 1925, Beck studied a class of exact solutions and interpreted them as representing the propagation of cylindrical gravitational waves (GWs) [24]. This class of solutions was later rediscovered by Einstein and Rosen in their seminal work on the studies of the nonlinearity of GWs in 1937 [137], and in the same year van Stockum solved the problem of a rigidly rotating infinitely long cylinder of dust, and found explicitly the corresponding metric [308]. In 1957, Bonnor [43] and Weber and Wheeler [327] studied the Einstein&#x2013;Rosen waves in great details, and since then, cylindrically symmetric spacetimes have been extensively investigated with various motivations [167, 294].</p>
</datas>]]
local dom = domobject.parse(sample)
tex.sprint(dom:query_selector("p")[1]:get_text())
\end{luacode*}
\end{document}
7

Both of the answers so far, by Skillmon and egreg, are excellent advice. There is one more important tip to make the line-breaking algorithm produce fewer hyphens.

\emergencystretch 3em

In LaTeX3, this will try to set troublesome paragraphs, such as the one you’re trying to avoid, with much longer spaces instead of bad hyphenation. Unlike the older \sloppy, this will not make good paragraphs look worse. You can restore the defaults with \fussy.

You must log in to answer this question.

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