TeX - LaTeX Asked by towi on April 28, 2021
Can I tell LaTeX that it may hyphen words that contain an underscore _
always before the underscore?
I have a lot of code examples in text, like is_error_condition_enum
and I would like to tell LaTeX it may hyphen this as:
Lorem ipsum is_error_-
condition_enum lorem.
always.
If that is not possible globally, how do I make an entry for some underscore-words like:
hyphenation{is_-error_-condition_-enum}
because that entry is rejected, obviously.
In sourcecode I write words like these as gpmono{isgpus{}errorgpus{}conditiongpus{}enum}
.
newcommand{gpus}{_discretionary{-}{}{}}
If gpus
is used in other places where hyphenation is not wanted, you can modify its definition only in the argument of gpmono
:
newcommand{gpmono}[1]{begingroup
renewcommand{gpus}{_discretionary{-}{}{}}%
ttfamily#1endgroup}
Of course, without knowing your original definitions of gpmono
and gpus
, I tried to guess.
Correct answer by egreg on April 28, 2021
The underscore
package provides a way to do this automatically: It modifies the defintion of the _
command in order to allow hyphenation after the underscore. Furthermore, it allows you to simply write _
instead of _
in text mode to produce an underscore. Everything you have to do is loading the package with
usepackage{underscore}
Answered by diabonas on April 28, 2021
The package hyphenat enables hyphenation in words that contain underscores.
For example, the following TeX:
documentclass{article}
usepackage{hyphenat}
begin{document}
Lorem_ipsum_dolor_sit_amet,_consetetur_sadipscing_elitr,_sed_diam_nonumy_eirmod_tempor_invidunt_ut_labore_et_dolore_magna_aliquyam_erat,_sed_diam_voluptua._At_vero_eos_et_accusam_et_justo_duo_dolores_et_ea_rebum._Stet_clita_kasd_gubergren,_no_sea_takimata_sanctus_est_Lorem_ipsum_dolor_sit_amet._Lorem_ipsum_dolor_sit_amet,_consetetur_sadipscing_elitr,_sed_diam_nonumy_eirmod_tempor_invidunt_ut_labore_et_dolore_magna_aliquyam_erat,_sed_diam_voluptua._At_vero_eos_et_accusam_et_justo_duo_dolores_et_ea_rebum._Stet_clita_kasd_gubergren,_no_sea_takimata_sanctus_est_Lorem_ipsum_dolor_sit_amet.
end{document}
As you can see, it does both hyphenation after underscores and within words.
Answered by tropappar on April 28, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP