Defining hyphen rules for word parts
Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
One can define optimal hyphenation of a single word in the preamble of a LaTeX document that will be used if line length is awkward.
hyphenationbiblio-philia
What if I wanted to be more general and define hyphenation for word parts:
% not real but imagined command:
hyphenation.+o-philia$
Adding a discretionary hyphen to any word that ends with ophilia after the o?
xetex hyphenation
add a comment |Â
up vote
3
down vote
favorite
One can define optimal hyphenation of a single word in the preamble of a LaTeX document that will be used if line length is awkward.
hyphenationbiblio-philia
What if I wanted to be more general and define hyphenation for word parts:
% not real but imagined command:
hyphenation.+o-philia$
Adding a discretionary hyphen to any word that ends with ophilia after the o?
xetex hyphenation
2
no, you could define a pattern but (unless you are using luatex) that requires building a new format, you can't usepatterns
in a normal document run (and tex patterns are not regex like that but you could match those characters at end of any word)
â David Carlisle
2 hours ago
Good to know! I'm actually using xelatex and not luatex.
â snoram
2 hours ago
The standard setting for American English hyphenatesbib-lio-philia
â egreg
1 min ago
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
One can define optimal hyphenation of a single word in the preamble of a LaTeX document that will be used if line length is awkward.
hyphenationbiblio-philia
What if I wanted to be more general and define hyphenation for word parts:
% not real but imagined command:
hyphenation.+o-philia$
Adding a discretionary hyphen to any word that ends with ophilia after the o?
xetex hyphenation
One can define optimal hyphenation of a single word in the preamble of a LaTeX document that will be used if line length is awkward.
hyphenationbiblio-philia
What if I wanted to be more general and define hyphenation for word parts:
% not real but imagined command:
hyphenation.+o-philia$
Adding a discretionary hyphen to any word that ends with ophilia after the o?
xetex hyphenation
xetex hyphenation
edited 2 hours ago
asked 3 hours ago
snoram
1446
1446
2
no, you could define a pattern but (unless you are using luatex) that requires building a new format, you can't usepatterns
in a normal document run (and tex patterns are not regex like that but you could match those characters at end of any word)
â David Carlisle
2 hours ago
Good to know! I'm actually using xelatex and not luatex.
â snoram
2 hours ago
The standard setting for American English hyphenatesbib-lio-philia
â egreg
1 min ago
add a comment |Â
2
no, you could define a pattern but (unless you are using luatex) that requires building a new format, you can't usepatterns
in a normal document run (and tex patterns are not regex like that but you could match those characters at end of any word)
â David Carlisle
2 hours ago
Good to know! I'm actually using xelatex and not luatex.
â snoram
2 hours ago
The standard setting for American English hyphenatesbib-lio-philia
â egreg
1 min ago
2
2
no, you could define a pattern but (unless you are using luatex) that requires building a new format, you can't use
patterns
in a normal document run (and tex patterns are not regex like that but you could match those characters at end of any word)â David Carlisle
2 hours ago
no, you could define a pattern but (unless you are using luatex) that requires building a new format, you can't use
patterns
in a normal document run (and tex patterns are not regex like that but you could match those characters at end of any word)â David Carlisle
2 hours ago
Good to know! I'm actually using xelatex and not luatex.
â snoram
2 hours ago
Good to know! I'm actually using xelatex and not luatex.
â snoram
2 hours ago
The standard setting for American English hyphenates
bib-lio-philia
â egreg
1 min ago
The standard setting for American English hyphenates
bib-lio-philia
â egreg
1 min ago
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
4
down vote
You can see the effect of patterns using Luatex
Underfull hbox (badness 10000) in paragraph at lines 8--8
TU/lmr/m/n/10 bibliophilia bibliophilias thingophilia
Underfull hbox (badness 10000) in paragraph at lines 13--13
TU/lmr/m/n/10 biblio-philia bibliophilias thingophilia
Underfull hbox (badness 10000) in paragraph at lines 18--18
TU/lmr/m/n/10 biblio-philia bibliophilias thingo-philia
Underfull hbox (badness 10000) in paragraph at lines 25--25
TU/lmr/m/n/10 biblio-philia biblio-philias thingo-philia
which is the terminal output from
% don't use the default US English patterns as biblio-philia already allowed there
% which spoils the example
newlanguagezzz
languagezzz
% nothing hyphenates
showhyphensbibliophilia bibliophilias thingophilia
hyphenationbiblio-philia
% just bibliophilia
showhyphensbibliophilia bibliophilias thingophilia
patternso9philia.% tied to end of word
% bibliophilia and thingophilia hyphenate
showhyphensbibliophilia bibliophilias thingophilia
newlanguagezzzb
languagezzzb
patternso9philia% not tied to end of word
% all hyphenate
showhyphensbibliophilia bibliophilias thingophilia
stop
Essentialy the same code would work with pdflatex or xelatex but you would have to modify the language files and build new formats with initex, you can not use patterns
in a normal tex run with classic tex.
add a comment |Â
up vote
4
down vote
If you're free to switch from XeLaTeX to LuaLaTeX, it's straightforward to set up a Lua function that adds a discretionary hyphenation point in words that contain "ophilia". In fact, as the following example shows, one can easily generalize the function so that it treats all words that contain either the letter a
or o
followed by either philia
or phobia
.
The only constraint imposed by this approach on your document is that you mustn't create and employ macros that contain the following strings: aphilia
, aphobia
, ophilia
, and/or ophobia
. E.g., setting newcommandagoraphobiazzz
or newcommandarachnophiliayyy
will definitely throw an error message. Hopefully, though, this constraint isn't exactly binding. Incidentally, macros named phobia
, philia
, AgoraPhobia
, and/or ArachnoPhilia
, would be just fine...
documentclassarticle
usepackageluacode
beginluacode
function ophilia ( s )
s = s:gsub ( "([ao])(philia)" , "%1\-%2" )
s = s:gsub ( "([ao])(phobia)" , "%1\-%2" )
return s
end
endluacode
AtBeginDocumentdirectlualuatexbase.add_to_callback(
"process_input_buffer", ophilia, "ophilia" )
%% just for this example:
setlengthtextwidth1mm
setlengthparindent0pt
begindocument
bibliophilia cryptophilia necrophilia agoraphilia
bibliophobia cryptophobia necrophobia agoraphobia
enddocument
but don't donewcommandagoraphilia zzz
in that case:-)
â David Carlisle
1 hour ago
@DavidCarlisle - True, I hadn't considered this possibility for practical insanity. :-) I'll post an addendum to state explicitly that a person who employs the method shown above shouldn't create macros whose names contain[ao]philia
or[ao]philia
...
â Mico
1 hour ago
1
for the ending given command names are unlikely but a reader might be encouraged by success with that ending to make all words ending intion
hyphenate as-tion
but thensection
might not work too well.....
â David Carlisle
1 hour ago
@DavidCarlisle - Do you approve of the extra paragraph I added a minute ago? :-)
â Mico
1 hour ago
1
i even voted:-)
â David Carlisle
1 hour ago
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
You can see the effect of patterns using Luatex
Underfull hbox (badness 10000) in paragraph at lines 8--8
TU/lmr/m/n/10 bibliophilia bibliophilias thingophilia
Underfull hbox (badness 10000) in paragraph at lines 13--13
TU/lmr/m/n/10 biblio-philia bibliophilias thingophilia
Underfull hbox (badness 10000) in paragraph at lines 18--18
TU/lmr/m/n/10 biblio-philia bibliophilias thingo-philia
Underfull hbox (badness 10000) in paragraph at lines 25--25
TU/lmr/m/n/10 biblio-philia biblio-philias thingo-philia
which is the terminal output from
% don't use the default US English patterns as biblio-philia already allowed there
% which spoils the example
newlanguagezzz
languagezzz
% nothing hyphenates
showhyphensbibliophilia bibliophilias thingophilia
hyphenationbiblio-philia
% just bibliophilia
showhyphensbibliophilia bibliophilias thingophilia
patternso9philia.% tied to end of word
% bibliophilia and thingophilia hyphenate
showhyphensbibliophilia bibliophilias thingophilia
newlanguagezzzb
languagezzzb
patternso9philia% not tied to end of word
% all hyphenate
showhyphensbibliophilia bibliophilias thingophilia
stop
Essentialy the same code would work with pdflatex or xelatex but you would have to modify the language files and build new formats with initex, you can not use patterns
in a normal tex run with classic tex.
add a comment |Â
up vote
4
down vote
You can see the effect of patterns using Luatex
Underfull hbox (badness 10000) in paragraph at lines 8--8
TU/lmr/m/n/10 bibliophilia bibliophilias thingophilia
Underfull hbox (badness 10000) in paragraph at lines 13--13
TU/lmr/m/n/10 biblio-philia bibliophilias thingophilia
Underfull hbox (badness 10000) in paragraph at lines 18--18
TU/lmr/m/n/10 biblio-philia bibliophilias thingo-philia
Underfull hbox (badness 10000) in paragraph at lines 25--25
TU/lmr/m/n/10 biblio-philia biblio-philias thingo-philia
which is the terminal output from
% don't use the default US English patterns as biblio-philia already allowed there
% which spoils the example
newlanguagezzz
languagezzz
% nothing hyphenates
showhyphensbibliophilia bibliophilias thingophilia
hyphenationbiblio-philia
% just bibliophilia
showhyphensbibliophilia bibliophilias thingophilia
patternso9philia.% tied to end of word
% bibliophilia and thingophilia hyphenate
showhyphensbibliophilia bibliophilias thingophilia
newlanguagezzzb
languagezzzb
patternso9philia% not tied to end of word
% all hyphenate
showhyphensbibliophilia bibliophilias thingophilia
stop
Essentialy the same code would work with pdflatex or xelatex but you would have to modify the language files and build new formats with initex, you can not use patterns
in a normal tex run with classic tex.
add a comment |Â
up vote
4
down vote
up vote
4
down vote
You can see the effect of patterns using Luatex
Underfull hbox (badness 10000) in paragraph at lines 8--8
TU/lmr/m/n/10 bibliophilia bibliophilias thingophilia
Underfull hbox (badness 10000) in paragraph at lines 13--13
TU/lmr/m/n/10 biblio-philia bibliophilias thingophilia
Underfull hbox (badness 10000) in paragraph at lines 18--18
TU/lmr/m/n/10 biblio-philia bibliophilias thingo-philia
Underfull hbox (badness 10000) in paragraph at lines 25--25
TU/lmr/m/n/10 biblio-philia biblio-philias thingo-philia
which is the terminal output from
% don't use the default US English patterns as biblio-philia already allowed there
% which spoils the example
newlanguagezzz
languagezzz
% nothing hyphenates
showhyphensbibliophilia bibliophilias thingophilia
hyphenationbiblio-philia
% just bibliophilia
showhyphensbibliophilia bibliophilias thingophilia
patternso9philia.% tied to end of word
% bibliophilia and thingophilia hyphenate
showhyphensbibliophilia bibliophilias thingophilia
newlanguagezzzb
languagezzzb
patternso9philia% not tied to end of word
% all hyphenate
showhyphensbibliophilia bibliophilias thingophilia
stop
Essentialy the same code would work with pdflatex or xelatex but you would have to modify the language files and build new formats with initex, you can not use patterns
in a normal tex run with classic tex.
You can see the effect of patterns using Luatex
Underfull hbox (badness 10000) in paragraph at lines 8--8
TU/lmr/m/n/10 bibliophilia bibliophilias thingophilia
Underfull hbox (badness 10000) in paragraph at lines 13--13
TU/lmr/m/n/10 biblio-philia bibliophilias thingophilia
Underfull hbox (badness 10000) in paragraph at lines 18--18
TU/lmr/m/n/10 biblio-philia bibliophilias thingo-philia
Underfull hbox (badness 10000) in paragraph at lines 25--25
TU/lmr/m/n/10 biblio-philia biblio-philias thingo-philia
which is the terminal output from
% don't use the default US English patterns as biblio-philia already allowed there
% which spoils the example
newlanguagezzz
languagezzz
% nothing hyphenates
showhyphensbibliophilia bibliophilias thingophilia
hyphenationbiblio-philia
% just bibliophilia
showhyphensbibliophilia bibliophilias thingophilia
patternso9philia.% tied to end of word
% bibliophilia and thingophilia hyphenate
showhyphensbibliophilia bibliophilias thingophilia
newlanguagezzzb
languagezzzb
patternso9philia% not tied to end of word
% all hyphenate
showhyphensbibliophilia bibliophilias thingophilia
stop
Essentialy the same code would work with pdflatex or xelatex but you would have to modify the language files and build new formats with initex, you can not use patterns
in a normal tex run with classic tex.
answered 2 hours ago
David Carlisle
469k3810991826
469k3810991826
add a comment |Â
add a comment |Â
up vote
4
down vote
If you're free to switch from XeLaTeX to LuaLaTeX, it's straightforward to set up a Lua function that adds a discretionary hyphenation point in words that contain "ophilia". In fact, as the following example shows, one can easily generalize the function so that it treats all words that contain either the letter a
or o
followed by either philia
or phobia
.
The only constraint imposed by this approach on your document is that you mustn't create and employ macros that contain the following strings: aphilia
, aphobia
, ophilia
, and/or ophobia
. E.g., setting newcommandagoraphobiazzz
or newcommandarachnophiliayyy
will definitely throw an error message. Hopefully, though, this constraint isn't exactly binding. Incidentally, macros named phobia
, philia
, AgoraPhobia
, and/or ArachnoPhilia
, would be just fine...
documentclassarticle
usepackageluacode
beginluacode
function ophilia ( s )
s = s:gsub ( "([ao])(philia)" , "%1\-%2" )
s = s:gsub ( "([ao])(phobia)" , "%1\-%2" )
return s
end
endluacode
AtBeginDocumentdirectlualuatexbase.add_to_callback(
"process_input_buffer", ophilia, "ophilia" )
%% just for this example:
setlengthtextwidth1mm
setlengthparindent0pt
begindocument
bibliophilia cryptophilia necrophilia agoraphilia
bibliophobia cryptophobia necrophobia agoraphobia
enddocument
but don't donewcommandagoraphilia zzz
in that case:-)
â David Carlisle
1 hour ago
@DavidCarlisle - True, I hadn't considered this possibility for practical insanity. :-) I'll post an addendum to state explicitly that a person who employs the method shown above shouldn't create macros whose names contain[ao]philia
or[ao]philia
...
â Mico
1 hour ago
1
for the ending given command names are unlikely but a reader might be encouraged by success with that ending to make all words ending intion
hyphenate as-tion
but thensection
might not work too well.....
â David Carlisle
1 hour ago
@DavidCarlisle - Do you approve of the extra paragraph I added a minute ago? :-)
â Mico
1 hour ago
1
i even voted:-)
â David Carlisle
1 hour ago
add a comment |Â
up vote
4
down vote
If you're free to switch from XeLaTeX to LuaLaTeX, it's straightforward to set up a Lua function that adds a discretionary hyphenation point in words that contain "ophilia". In fact, as the following example shows, one can easily generalize the function so that it treats all words that contain either the letter a
or o
followed by either philia
or phobia
.
The only constraint imposed by this approach on your document is that you mustn't create and employ macros that contain the following strings: aphilia
, aphobia
, ophilia
, and/or ophobia
. E.g., setting newcommandagoraphobiazzz
or newcommandarachnophiliayyy
will definitely throw an error message. Hopefully, though, this constraint isn't exactly binding. Incidentally, macros named phobia
, philia
, AgoraPhobia
, and/or ArachnoPhilia
, would be just fine...
documentclassarticle
usepackageluacode
beginluacode
function ophilia ( s )
s = s:gsub ( "([ao])(philia)" , "%1\-%2" )
s = s:gsub ( "([ao])(phobia)" , "%1\-%2" )
return s
end
endluacode
AtBeginDocumentdirectlualuatexbase.add_to_callback(
"process_input_buffer", ophilia, "ophilia" )
%% just for this example:
setlengthtextwidth1mm
setlengthparindent0pt
begindocument
bibliophilia cryptophilia necrophilia agoraphilia
bibliophobia cryptophobia necrophobia agoraphobia
enddocument
but don't donewcommandagoraphilia zzz
in that case:-)
â David Carlisle
1 hour ago
@DavidCarlisle - True, I hadn't considered this possibility for practical insanity. :-) I'll post an addendum to state explicitly that a person who employs the method shown above shouldn't create macros whose names contain[ao]philia
or[ao]philia
...
â Mico
1 hour ago
1
for the ending given command names are unlikely but a reader might be encouraged by success with that ending to make all words ending intion
hyphenate as-tion
but thensection
might not work too well.....
â David Carlisle
1 hour ago
@DavidCarlisle - Do you approve of the extra paragraph I added a minute ago? :-)
â Mico
1 hour ago
1
i even voted:-)
â David Carlisle
1 hour ago
add a comment |Â
up vote
4
down vote
up vote
4
down vote
If you're free to switch from XeLaTeX to LuaLaTeX, it's straightforward to set up a Lua function that adds a discretionary hyphenation point in words that contain "ophilia". In fact, as the following example shows, one can easily generalize the function so that it treats all words that contain either the letter a
or o
followed by either philia
or phobia
.
The only constraint imposed by this approach on your document is that you mustn't create and employ macros that contain the following strings: aphilia
, aphobia
, ophilia
, and/or ophobia
. E.g., setting newcommandagoraphobiazzz
or newcommandarachnophiliayyy
will definitely throw an error message. Hopefully, though, this constraint isn't exactly binding. Incidentally, macros named phobia
, philia
, AgoraPhobia
, and/or ArachnoPhilia
, would be just fine...
documentclassarticle
usepackageluacode
beginluacode
function ophilia ( s )
s = s:gsub ( "([ao])(philia)" , "%1\-%2" )
s = s:gsub ( "([ao])(phobia)" , "%1\-%2" )
return s
end
endluacode
AtBeginDocumentdirectlualuatexbase.add_to_callback(
"process_input_buffer", ophilia, "ophilia" )
%% just for this example:
setlengthtextwidth1mm
setlengthparindent0pt
begindocument
bibliophilia cryptophilia necrophilia agoraphilia
bibliophobia cryptophobia necrophobia agoraphobia
enddocument
If you're free to switch from XeLaTeX to LuaLaTeX, it's straightforward to set up a Lua function that adds a discretionary hyphenation point in words that contain "ophilia". In fact, as the following example shows, one can easily generalize the function so that it treats all words that contain either the letter a
or o
followed by either philia
or phobia
.
The only constraint imposed by this approach on your document is that you mustn't create and employ macros that contain the following strings: aphilia
, aphobia
, ophilia
, and/or ophobia
. E.g., setting newcommandagoraphobiazzz
or newcommandarachnophiliayyy
will definitely throw an error message. Hopefully, though, this constraint isn't exactly binding. Incidentally, macros named phobia
, philia
, AgoraPhobia
, and/or ArachnoPhilia
, would be just fine...
documentclassarticle
usepackageluacode
beginluacode
function ophilia ( s )
s = s:gsub ( "([ao])(philia)" , "%1\-%2" )
s = s:gsub ( "([ao])(phobia)" , "%1\-%2" )
return s
end
endluacode
AtBeginDocumentdirectlualuatexbase.add_to_callback(
"process_input_buffer", ophilia, "ophilia" )
%% just for this example:
setlengthtextwidth1mm
setlengthparindent0pt
begindocument
bibliophilia cryptophilia necrophilia agoraphilia
bibliophobia cryptophobia necrophobia agoraphobia
enddocument
edited 14 mins ago
answered 2 hours ago
Mico
265k30356736
265k30356736
but don't donewcommandagoraphilia zzz
in that case:-)
â David Carlisle
1 hour ago
@DavidCarlisle - True, I hadn't considered this possibility for practical insanity. :-) I'll post an addendum to state explicitly that a person who employs the method shown above shouldn't create macros whose names contain[ao]philia
or[ao]philia
...
â Mico
1 hour ago
1
for the ending given command names are unlikely but a reader might be encouraged by success with that ending to make all words ending intion
hyphenate as-tion
but thensection
might not work too well.....
â David Carlisle
1 hour ago
@DavidCarlisle - Do you approve of the extra paragraph I added a minute ago? :-)
â Mico
1 hour ago
1
i even voted:-)
â David Carlisle
1 hour ago
add a comment |Â
but don't donewcommandagoraphilia zzz
in that case:-)
â David Carlisle
1 hour ago
@DavidCarlisle - True, I hadn't considered this possibility for practical insanity. :-) I'll post an addendum to state explicitly that a person who employs the method shown above shouldn't create macros whose names contain[ao]philia
or[ao]philia
...
â Mico
1 hour ago
1
for the ending given command names are unlikely but a reader might be encouraged by success with that ending to make all words ending intion
hyphenate as-tion
but thensection
might not work too well.....
â David Carlisle
1 hour ago
@DavidCarlisle - Do you approve of the extra paragraph I added a minute ago? :-)
â Mico
1 hour ago
1
i even voted:-)
â David Carlisle
1 hour ago
but don't do
newcommandagoraphilia zzz
in that case:-)â David Carlisle
1 hour ago
but don't do
newcommandagoraphilia zzz
in that case:-)â David Carlisle
1 hour ago
@DavidCarlisle - True, I hadn't considered this possibility for practical insanity. :-) I'll post an addendum to state explicitly that a person who employs the method shown above shouldn't create macros whose names contain
[ao]philia
or [ao]philia
...â Mico
1 hour ago
@DavidCarlisle - True, I hadn't considered this possibility for practical insanity. :-) I'll post an addendum to state explicitly that a person who employs the method shown above shouldn't create macros whose names contain
[ao]philia
or [ao]philia
...â Mico
1 hour ago
1
1
for the ending given command names are unlikely but a reader might be encouraged by success with that ending to make all words ending in
tion
hyphenate as -tion
but then section
might not work too well.....â David Carlisle
1 hour ago
for the ending given command names are unlikely but a reader might be encouraged by success with that ending to make all words ending in
tion
hyphenate as -tion
but then section
might not work too well.....â David Carlisle
1 hour ago
@DavidCarlisle - Do you approve of the extra paragraph I added a minute ago? :-)
â Mico
1 hour ago
@DavidCarlisle - Do you approve of the extra paragraph I added a minute ago? :-)
â Mico
1 hour ago
1
1
i even voted:-)
â David Carlisle
1 hour ago
i even voted:-)
â David Carlisle
1 hour ago
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f453634%2fdefining-hyphen-rules-for-word-parts%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
2
no, you could define a pattern but (unless you are using luatex) that requires building a new format, you can't use
patterns
in a normal document run (and tex patterns are not regex like that but you could match those characters at end of any word)â David Carlisle
2 hours ago
Good to know! I'm actually using xelatex and not luatex.
â snoram
2 hours ago
The standard setting for American English hyphenates
bib-lio-philia
â egreg
1 min ago