5

I have huge Russian text and I am trying to build simple solution to have ability off/on hyphenations in the text, in the text numbers and dates as a plane text are possible.

I have tried some variants that didn't work correctly. How to prevent LaTeX from hyphenating the entire document?. This post was as a start point, also I have tried recommendations from this post: hyphsubst conflicts with inputenc.

My code, theoretically problem can be that I have been using babel package:

\documentclass[11pt,a4paper]{article}

\usepackage[T1,T2A,T2B,T2C]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[russian]{babel}

%Added package.
\usepackage{geometry}
\geometry{lmargin=1.18in, rmargin = 0.5in, tmargin = 1.08in, bmargin=0.6in}
\begin{document}
Длинный текст, который не переноситься корректно, особенно если в него добавить длинные слова и номера, например даты рождения 01.01.2001 или еще какие-нибудь цифры, 10000131342424.
\end{document}

To summarize, I need some library or trick that will break lines correctly without hyphenations if possible. The main problem that I have encountered with solutions from linked posts, words were outside the borders of the document.

Edit: Although I am using geometry that may produce problems. Solutions presented below does not work for code above.(I have added only geometry package).

  • 1
    What exactly would you like to happen when the line is too wide for the page? If you disallow hyphenation, TeX has limited options, so text is much more likely to end up in the margins because TeX is much less likely to be able to figure out good line breaks. (You will get more 'bad box' warnings on the console. – cfr Dec 28 '15 at 01:57
  • TeX does a very good job at avoiding hyphenating by itself. If hyphenating is wrong, that is another problem entirely. – vonbrand Dec 28 '15 at 11:48
  • The main problem with all solutions I have words outside geometry boundaries of document. – Dmytro Chasovskyi Dec 28 '15 at 15:08

2 Answers2

5

Use the hyphenrules environment with the special nohyphenation (pseudo)language.

\documentclass[11pt,a4paper]{article}

\usepackage[T1,T2A,T2B,T2C]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[russian]{babel}

\begin{document}

Длинный текст, который не переноситься корректно, особенно
если в него добавить длинные слова и номера, например даты
рождения 01.01.2001 или еще какие-нибудь цифры, 10000131342424.

\begin{hyphenrules}{nohyphenation}
Длинный текст, который не переноситься корректно, особенно
если в него добавить длинные слова и номера, например даты
рождения 01.01.2001 или еще какие-нибудь цифры, 10000131342424.
\end{hyphenrules}

\end{document}

enter image description here

egreg
  • 1,121,712
  • The problem with this solution that if I have words that outside geometry boundaries of document. For instance, Problem with boundaries picture. And solution above does not solve it for some reason, even for plane text. – Dmytro Chasovskyi Dec 28 '15 at 15:06
  • @DmitriyChasovskoy Hyphenation is exactly meant for avoiding those problems. – egreg Dec 28 '15 at 17:04
  • For some reasons, it didn't work. I have tried exactly your solution, but nothing happens. I believe that it may work, therefore, I have voted for your solution, but in my project it didn't. Answer that I have marked work only with \raggedright. – Dmytro Chasovskyi Dec 29 '15 at 11:14
  • @DmitriyChasovskoy What TeX distribution are you using? With MiKTeX you may need to explicitly enable nohyphenation using its wizard. – egreg Dec 29 '15 at 11:20
4

You could try something like this:

\newcommand*{\nohyphens}{\hyphenpenalty=10000\exhyphenpenalty=10000\relax}

To limit the scope of the command, include it in a group. For example, surround the command and text with curly brackets:

{\nohyphens
  Длинный текст, который не переноситься корректно, особенно если в него добавить длинные слова и номера, например даты рождения 01.01.2001 или еще какие-нибудь цифры, 10000131342424.

}

hyphenated and non-hyphenated text

Note that by prohibiting hyphenation, you reduce the options TeX has for finding good line breaks. This will result in more bad boxes and more cases where text flows into the margin. You can temporarily relax the typographical standards TeX imposes on itself using:

\sloppypar

Or you can switch off justification for the non-hyphenated text:

{\nohyphens\raggedright
  Длинный текст, который не переноситься корректно, особенно если в него добавить длинные слова и номера, например даты рождения 01.01.2001 или еще какие-нибудь цифры, 10000131342424.

}

Complete code for minimal example above:

\documentclass[11pt,a4paper]{article}
\newcommand*{\nohyphens}{\hyphenpenalty=10000\exhyphenpenalty=10000\relax}
\usepackage[T1,T2A,T2B,T2C]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[russian]{babel}

\begin{document}
Длинный текст, который не переноситься корректно, особенно если в него добавить длинные слова и номера, например даты рождения 01.01.2001 или еще какие-нибудь цифры, 10000131342424.

{\nohyphens
  Длинный текст, который не переноситься корректно, особенно если в него добавить длинные слова и номера, например даты рождения 01.01.2001 или еще какие-нибудь цифры, 10000131342424.

}

\end{document}
cfr
  • 198,882