3

I am sure this is some basic LaTeX document formatting, but for the sake of me I just can't find the right place in the documentation on the proper way to achieve what I want.

Consider the following MWE:

\documentclass[12pt]{article}

\usepackage[T2A]{fontenc}
\usepackage[utf8]{inputenc}

\sloppypar

\begin{document}
    Some normal line followed by a cyrillic long word многодългадуманакирилицабезпренасяне
\end{document}

I know \sloppypar is a bad practice, but it really did manage most of my warnings and document flaws in an acceptable way, so I'm sticking to that for now.

This example compiles with an Underfull \hbox (badness 10000) in paragraph at lines 9--10 warning, which is understandable since LaTeX doesn't have instructions on how to hyphenate the cyrillic word in question and thus puts it on a whole new line, while trying to stretch the previous line, which ends up as Underfull. I get this. (And by the way, this is not Russian, but Bulgarian, and I didn't find any hyphenation packages for that... so advices on that note are also welcome).

Essence: I really don't have the time to reformat my whole document right now, so I'd want to instruct LaTeX simply not to try to stretch the previous line (basically break it like with \\ where needed), which satisfies me completely for now. So the document should look as if its content was the following:

\documentclass[12pt]{article}

\usepackage[T2A]{fontenc}
\usepackage[utf8]{inputenc}

\sloppypar

\begin{document}
    Some normal line followed by a cyrillic long word\\ многодългадуманакирилицабезпренасяне
\end{document}

For now, I'm actually fixing the couple of spots (maybe 10 or 15 lines) where this problem occurs, by manually adding the \\ and I know it's horrible and hardly managable in the long term, so I'd be really glad on some instructions on how to enforce such behaviour (in combination with \sloppypar if that's possible).

Many thanks in advance!

13
  • 1
    Since you mentioned, you couldn't find any hyphenation packages for the bulgarian language, ctan.org/pkg/babel-bulgarian might be interesting.
    – leandriis
    Nov 17, 2020 at 18:24
  • If your document is mostly in english with some bulgarian words in it, the following should sork: \documentclass[12pt]{article} \usepackage[T2A]{fontenc} \usepackage[utf8]{inputenc} \usepackage[english]{babel} \sloppypar \begin{document} Some normal line followed by a cyrillic long word \foreignlanguage{bulgarian}{многодългадуманакирилицабезпренасяне} \end{document}.
    – leandriis
    Nov 17, 2020 at 18:27
  • 1
    If you use bulgarian text only, a simple \usepackage[bulgarian]{babel} should already result in the expected output.
    – leandriis
    Nov 17, 2020 at 18:32
  • 1
    Should the rest of your text stay fully justified and just this one line of text (the line before the too long word) should be left aligned or do you prefer your whole text left aligned?
    – leandriis
    Nov 17, 2020 at 18:38
  • 1
    As an alternative to using babel with an appropriate language option, I'd just add discretionary hyphens in appropriate places and let (La)TeX choose the one(s) that give the best breaks. A discretionary hyphen consists of a backslash followed by a hyphen \- and it works very reliably. (It's sometimes needed in all-English texts for words that should be hyphenated, but automatic hyphenation can't be applied because it's different depending on whether the word functions as a verb or a noun, like "progress".) Nov 17, 2020 at 21:59

2 Answers 2

4

I'm surprised that no one has suggested using "discretionary hyphens". A discretionary hyphen is input as backslash-hyphen (\-) in locations in a word where hyphenation is appropriate.

Discretionary hyphens are sometimes needed in English text where a word that can and should be hyphenated cannot be hyphenated automatically, because (La)TeX can't tell whether it's a verb or a noun, and the break should be in a different place depending on whether the word is used a a verb or a noun, for example "pro\-gress" (verb) vs. "prog\-ress" (noun).

Let's try this with your long cyrillic word:

много\-дълга\-дума\-на\-кирилица\-без\-пре\-насяне

(La)TeX will choose the break(s) that will give the best spacing within the current paragraph.

(Please don't assume this is entirely correct. My grasp of Bulgarian is rather shaky; I could probably do better with Russian.)

Addendum:

The OP has noted in a comment that the document in question contains more than just a smattering of Bulgarian text. In that case, this approach is almost certainly preferable:

\usepackage[bulgarian]{babel}

@leandris has proposed the following in a comment:

\documentclass[12pt]{article}
 \usepackage[T2A]{fontenc}
 \usepackage[utf8]{inputenc}
 \usepackage[english]{babel}
% \sloppypar
\begin{document}
Some normal line followed by a cyrillic long word
\foreignlanguage{bulgarian}{многодългадуманакирилицабезпренасяне}
\end{document}

I recommend checking the babel documentation to determine how to deal with more extensive packages of the "other" language.

3
  • Your grasp of Bulgarian is astoundingly correct, with exception for the last two syllables of the last word! Thank you for the suggestion! But as mentioned in the comments, my document is mainly in Bulgarian where this behaviour occurs. The english text in the example was just for the read to grasp the problem. Do you have any suggestions for the main question? How to force LaTeX to break the lines as with `\`?
    – D. Petrov
    Nov 17, 2020 at 22:31
  • 1
    If the bulk of the document is Bulgarian, then using babel with the [bulgarian] option is undoubtedly preferable. But in that case, this question is almost certainly a duplicate. (I haven't looked for one, but it likely wouldn't specify Bulgarian.) I'll add that to the answer though; even with good hyphenation patterns for Bulgarian, an occasional discretionary might be useful. Nov 17, 2020 at 22:39
  • Thank you so much for the detailed information!
    – D. Petrov
    Nov 18, 2020 at 3:40
5

TeX has been multilingual for many years.

\documentclass[12pt]{article}

\usepackage[T2A,T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[bulgarian,english]{babel}

\usepackage{showframe} % to show page margins

\begin{document}

Some normal line followed by a cyrillic long word 
\foreignlanguage{bulgarian}{многодългадуманакирилицабезпренасяне}

\end{document}

enter image description here

If your document is mainly in Bulgarian, with English text, swap:

\documentclass[12pt]{article}

\usepackage[T2A,T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english,bulgarian]{babel}

\usepackage{showframe} % to show page margins

\begin{document}

\foreignlanguage{english}{Some normal line followed by a cyrillic long word} 
многодългадуманакирилицабезпренасяне

\end{document}

If you don't like that hyphenation because of the compound word, you can use "= to set a compoind word boundary. Here's the result and also the complete hyphenation in this case.

\documentclass[12pt]{article}

\usepackage[T2A,T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english,bulgarian]{babel}

\usepackage{showframe} % to show page margins

\begin{document}

\foreignlanguage{english}{Some normal line followed by a cyrillic long word}
многодългадумана"=кирилицабезпренасяне

\parbox[t]{0pt}{\hspace{0pt}многодългадуманакирилицабезпренасяне}

\end{document}

enter image description here

From the documentation of babel-bulgarian:

enter image description here

Note that ‘‘ should really be " (undirected double quote), so the real shorthands are

"-
""
"~
"=
",
1
  • I'm really grateful for the provided examples and the detailed explanation!
    – D. Petrov
    Nov 18, 2020 at 3:41

You must log in to answer this question.

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