Text FormattingNo Hyphenation for too long Words

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
fibonacci2
Posts: 9
Joined: Wed Feb 01, 2012 12:41 am

No Hyphenation for too long Words

Post by fibonacci2 »

Hi guys!

In my text I have some very long words (names of function) like, for instance, "put_3_apples_and_2_oranges_in_the_bag()".

These words don't respect the margin or, even, they go out off the page. Here an example is (you can try to generate pdf):

Code: Select all

\documentclass[oneside]{book}
\usepackage[T1]{fontenc}
\usepackage{selinput}
\SelectInputMappings{
  agrave={à},
  igrave={ì},
  Euro={€}
}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\usepackage{verbatim}
\usepackage[italian,english]{babel}
\usepackage{color}
\usepackage{graphicx}
\usepackage{algorithm}
\usepackage[noend]{algorithmic}
\usepackage{amsfonts}
\usepackage{amsmath}
\newcommand{\argmin}{\operatornamewithlimits{arg\ min}}
\usepackage{float}

\begin{document}

Notice that XXXX could be solved by repeatedly calling place\_3\_apples($A$,$B$,$B_2$,$C$), as shown by the following pseudocode.

Word word word. This version corresponds to what in experiments is called "xxxxxx x", so place\_$A_1$\_xxxxxxxx\_one\_by\_one\_xx() can be renamed place\_$A_1$\_xxxxxxxx\_one\_by\_one\_xx\_xx() (and similarly place\_1\_xxxxxxx\_xx() can be renamed place\_1\_xxxxxxx\_xx\_xx()).

\end{document}
How could I solve this problem?

I'd like see either long words on new lines (in such a way that justification and margin are respected) or split into two lines...

Thanks!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

No Hyphenation for too long Words

Post by localghost »

Please get used to always providing a proper minimal example that contains only the relevant parts and not code that is not necessary to reproduce the problem.

The reason why those expressions are not hyphenated is that there are simply no hyphenation patterns for such exceptions. You can try to predetermine hyphenation points by the \hyphenation (← Link!) command. In this case the seqsplit package might be the better alternative.

Code: Select all

\documentclass[oneside,italian,english]{book}
\usepackage[T1]{fontenc}
\usepackage{selinput}
\SelectInputMappings{
  agrave={à},
  igrave={ì},
  Euro={€}
}
\usepackage{babel}
\usepackage{seqsplit}

%\renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi}   % for hyphens

\begin{document}
  Notice that XXXX could be solved by repeatedly calling \seqsplit{place\_3\_apples({$A$,$B$,$B_2$,$C$})}, as shown by the following pseudocode.

  Word word word. This version corresponds to what in experiments is called "xxxxxx x", so \seqsplit{place\_{$A_1$}\_xxxxxxxx\_one\_by\_one\_xx()} can be renamed \seqsplit{place\_{$A_1$}\_xxxxxxxx\_one\_by\_one\_xx\_xx()} (and similarly \seqsplit{place\_1\_xxxxxxx\_xx()} can be renamed place\_1\_xxxxxxx\_xx\_xx()).
\end{document}
Note that math expressions need to be grouped by additional curly braces (see code above).


Thorsten
fibonacci2
Posts: 9
Joined: Wed Feb 01, 2012 12:41 am

No Hyphenation for too long Words

Post by fibonacci2 »

Ok thanks!
But I can't use \hyphenation to force \seqsplit to split words where I wish since \hyphenation accepts only characters and hyphens.
For instance, if I do

Code: Select all

\hyphenation{place\_3\_-apples(-{$A$,$B$,$B_2$,$C$})}
I get an error.
How could I predetermine the hyphenation points?
For instance, I'd like have breakpoints only after underscores.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

No Hyphenation for too long Words

Post by localghost »

Then you need to give the hyphenation points explicitly for every single occurrence of such an expression in the running text.

Code: Select all

place\_\-$A_1$\_\-xxxxxxxx\_\-one\_\-by\_\-one\_\-xx\_\-xx()
Success will be very limited contrary to the method by the seqsplit package.
fibonacci2
Posts: 9
Joined: Wed Feb 01, 2012 12:41 am

No Hyphenation for too long Words

Post by fibonacci2 »

OK Thanks!
But why need I put input parameters in curly brackets? like

Code: Select all

function({$N_1$,$N_2$})
instead of

Code: Select all

function($N_1$,$N_2$)
Why is not the latter one right?
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

No Hyphenation for too long Words

Post by localghost »

fibonacci2 wrote:[…] But why need I put input parameters in curly brackets? […]
Because otherwise seqsplit will simply not work and emit erors.
fibonacci2
Posts: 9
Joined: Wed Feb 01, 2012 12:41 am

Re: No Hyphenation for too long Words

Post by fibonacci2 »

OK!
Post Reply