Benjamin Lee
Benjamin Lee

Reputation: 501

Stop Sphinx from Hyphenating

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?

Upvotes: 3

Views: 1271

Answers (2)

yoonghm
yoonghm

Reputation: 4625

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).

Upvotes: 0

Steve Piercy
Steve Piercy

Reputation: 15055

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

Upvotes: 3

Related Questions