3

I have a similar question to this, except for Sphinx and RST. Namely, I would like to prevent text from being hyphenated at the end of the line.

For example I want this:

This is my long sent-
ence.

To be:

This is my long
sentence.

How do I do this?

mzjn
  • 48,958
  • 13
  • 128
  • 248
Benjamin Lee
  • 481
  • 1
  • 5
  • 15

2 Answers2

2

Hyphenation is implemented by the stylesheet basic.css in the Sphinx theme "basic".

div.body p, div.body dd, div.body li, div.body blockquote {
    -moz-hyphens: auto;
    -ms-hyphens: auto;
    -webkit-hyphens: auto;
    hyphens: auto;
}

You can override these styles with your own. See my answer to How do I customize Sphinx RtD Theme default search settings?

Your theme may have JavaScript or other styles that implement hyphenation.

For PDF output, see https://tex.stackexchange.com/a/5039

Steve Piercy
  • 13,693
  • 1
  • 44
  • 57
  • I copy `basic.css_t` to `_static` folder of my project. This method only works for HTML output but not Latex/PDF outputs. – yoonghm Dec 19 '18 at 14:37
  • I am still looking for solution to stop Sphinx to use hyphenation for Latex/PDF outputs. – yoonghm Dec 19 '18 at 14:43
  • Answer edited after performing a [DuckDuckGo search](https://duckduckgo.com/?q=no+hyphenation+latex) – Steve Piercy Dec 19 '18 at 18:12
0

After reading pointers from @steve-piercy, I managed to find a solution for the problem. I need to customize conf.py in my project. My conf.py has the following settings:

# ...
# ...

# -- Options for LaTeX output ------------------------------------------------

latex_elements = {
    # The paper size ('letterpaper' or 'a4paper').
    #
    'papersize': 'a4paper',

    # The font size ('10pt', '11pt' or '12pt').
    #
    'pointsize': '12pt',

    # Additional stuff for the LaTeX preamble.
    #
    'preamble': r'''
    \usepackage[none]{hyphenat}
    '''

    # Latex figure (float) alignment
    #
    # 'figure_align': 'htbp',

}

# ...
# ...

I am using Sphinx 1.8.2, MikTex 2.9 and Strawberry Perl 5.28.1. This new change in conf.py will download new perl package(s).

yoonghm
  • 4,198
  • 1
  • 32
  • 48
  • what do you mean about Perl packages? this looks quite unrelated to using the LaTeX [`hyphenat`](http://www.ctan.org/pkg/hyphenat) package in your document. –  Jan 01 '19 at 09:48
  • AFAIK, those packages are written in Perl. Perl will download missing packages on its own. – yoonghm Jan 01 '19 at 14:01
  • the manager of your TeX installation is quite possibly written in Perl: I don't know about MikTeX, but the `tlmgr` for TeXLive is indeed a Perl script. But `hyphenat` is simply a bunch of LaTeX macros and TeX primitive register settings (such as `\hyphenpenalty=10000\exhyphenpenalty=10000\relax`) having nothing whatsoever to do with Perl. –  Jan 01 '19 at 22:01