# how to implement customized hyphenation patterns

I created a file with nonstandard hyphenation patterns of my own, but I do not know how to force LaTeX into using my patterns instead of the default ones.

I am using Linux Mint, with pdflatex to compile my '.tex' files. I discovered a dumylang option and a dumyhyph.tex file, meant for "testing new hyphenation patterns", which is exactly what I wish to do. So far, however, I have not been able to activate them.

My file of patterns has the following content:

\patterns{
1p 1t 1c 1k 1j 1w t2r
1fe 1fa 1fo 1fi 1fy 1fu
1re 1ra 1ro 1ri 1ry 1ru
1se 1sa 1so 1si 1sy 1su
%
%...deleted lines...
%
kyle me2ke ky2nu ni2e fa2l r2ke
u2je u2ma i2jau ru2me
e2m a2m o2m i2m y2m u2m nh2ma nh2mu
3e2le 3e2la 3e2lo 3e2li 3e2ly 3e2lu
}
%\dump


How should I proceed? (Please be detailed, since my experience with TeX and Linux is very limited)

• you need to remake the format (or use luatex) in classic tex pdftex and xetex patterns can only be loaded at format making time, not in a normal typesetting run Aug 19, 2016 at 22:34
• Not writing an answer because I’ve never tried this myself, but, as far as I know, it should suffice to save your hyphenation pattern file into $TEXMFHOME/tex/generic/hyphen/dumyhyph.tex (say) and rebuild the format. – GuM Aug 19, 2016 at 22:45 • … assuming that you have got TeX Live! (:-) – GuM Aug 19, 2016 at 22:52 • @Gustavo Mezzetti: I do not have a folder "$TEXMFHOME/tex/generic/hyphen", but I do have a folder "/usr/share/texmf-texlive/tex/generic/hyphen", where I placed my hyphenation patterns. When I try to run "update-language-dat" from a terminal it asks for "the configuration directory", but I do not have an idea where such a directory might be, whether I should create it, or what its use is. Aug 20, 2016 at 12:02
• @Goswin: 1) Type kpsewhich -var-value TEXMFHOME to learn what $TEXFHOME should expand to on your system. 2) Let’s say the answer is /home/mickeymo/texmf; then you should create any directory in the path /home/mickeymo/texmf/tex/generic/hyphen/ that doesn’t exist yet; after this, try proceeding as I’ve indicated in my previous comment. There shouldn’t be any need to rebuild the language.dat file, only the TeX format(s) need to be rebuilt (but remember, I’ve never actually tried this out! :-) . – GuM Aug 20, 2016 at 13:14 ## 1 Answer The partial answer I tried to give in my comments to the question couldn’t work, for at least two reasons: • a format file in the personal texmf tree ($TEMFHOME) is not permitted to override a system format file by the same name (quite wisely);

• in any case, the name of the format for the pdfTeX engine should be pdflatex.fmt, not latex.fmt.

So, the best thing is to give the custom format a custom name (seems wise too). I’ll explain step by step a possible way to proceed, that, this time, I tested myself. Please note that the following instructions assume a TeX Live distribution!

First of all, create a temporary directory in any location of your file system; henceforth, this directory will be referred to as FOO/. Next, let’s say that your custom hyphenation file looks like this:

% It's a dummy file dumyhyph.tex created for testing purposes.
% This file is normally defined in language.dat et may be used by language
% styles such as french.sty to define a temporary language. B. Gaulle 23/10/91

\begingroup
\patterns{ % dummy patterns
.ach4
z4zy
% I add a pattern that does permit hyphenation:
aa5a
% (hyphenation will be possible only at places where at least three consecutive
% "a" characters occur).
}
\endgroup


This is only an example, of course, but it is the example I shall use below. Note that it defines only one permissible hyphenation, namely aa-a.

We’ll add at the end of this file the following line

\gdef\ParapaPonziPonziPo{*** This is my home-made LaTeX format! ***}


We do so just to have a means to check with greater ease that our custom format, and not the system one, is being loaded during a TeX run. So, our file now looks like this:

% It's a dummy file dumyhyph.tex created for testing purposes.
% This file is normally defined in language.dat et may be used by language
% styles such as french.sty to define a temporary language. B. Gaulle 23/10/91

\begingroup
\patterns{ % dummy patterns
.ach4
z4zy
% I add a pattern that does permit hyphenation:
aa5a
% (hyphenation will be possible only at places where at least three consecutive
% "a" characters occur).
}
\endgroup
\gdef\ParapaPonziPonziPo{*** This is my home-made LaTeX format! ***}


Save it in FOO/dumyhyph.tex; note that the basename dumyhyph.tex must be used. After this, make FOO your current directory.

We’ll call our custom format pdflatexmyhyphen; so, from within the FOO directory, issue the following command at the shell prompt:

pdflatex -ini -etex -jobname pdflatexmyhyphen pdflatex.ini


After a short while, you’ll get the shell prompt again; you should now find that FOO contains the following files:

dumyhyph.tex
pdflatexmyhyphen.fmt
pdflatexmyhyphen.log
texsys.aux


Spend a minute to take a look at the transcript file pdflatexmyhyphen.log; scroll down until you find where it says

===========================================
Local configuration file hyphen.cfg used
===========================================


…some lines omitted…

\l@usenglish=\language0
\l@USenglish=\language0
\l@american=\language0
\l@dumylang=\language1

(./dumyhyph.tex)


The lines that says (./dumyhyph.tex) proves that the file dumyhyph.tex was input from the current directory, contrary to the other hyphenation pattern files.

OK, now run the command

kpsewhich -var-value TEXMFHOME


to learn where your system assumes your personal texmf tree is located; let’s say that the answer is

/home/donalddu/texmf


Then, create any missing directory in the path

/home/donalddu/texmf/web2c/


(note that /home/donalddu/ is supposed to be your home directory, so you can do so without any need for super-user privileges); finally, move—or copy—the file pdflatexmyhyphen.fmt from FOO/ to /home/donalddu/texmf/web2c/.

That’s all; as @cfr remarked, there’s no need to run mktexlsr: your custom format, containing your custom hyphenation patterns, is ready for use.

So, let’s try it out, by compiling the following file—let us call it TryMyHyphenation.tex:

% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly
% declare the paper format.

\usepackage[T1]{fontenc}         % Not always necessary, but recommended.
% End of standard header.  What follows pertains to the problem at hand.

\ifdefined\ParapaPonziPonziPo
\typeout{\ParapaPonziPonziPo}
\fi

\usepackage[english]{babel}

\begin{document}

This is a paragraph written in English, to which English hyphenation rules
apply.  It is followed by some other paragraphs written in our dummy
language''; in order to make our custom hyphenation rules apply to them, we
enclose them within a \texttt{hyphenrules} environment.

\begin{hyphenrules}{dumylang}

The dummy language'' is curiously similar to English, except that it doesn't
permit words to be hyphenated at all---or almost so.  Indeed, a peculiarity of
this language is that it includes non-English words like
mumbawohckijutresxxiukklanghornitudinal'' and axaxaxaaaxaxaxa'', and
that---aha!---hyphenation is permitted when three~a'' occur in a row.  So,
while, for example, mumbawohckijutresxxiukklanghornitudinal'' cannot be
broken, and hence produces overfull \verb|\hbox|es'', the word
axaxaxaaaxaxaxa'' \emph{can} be hyphenated, provided, of course, that you are
using a \LaTeX\ format that incorporates our custom hyphenation patterns.

Another paragraph that again demonstrate this: pneumococcus, axaxaxaaaxaxaxa,
hyperbola, neutrino.

\end{hyphenrules}

\end{document}


First, try compiling it with the normal LaTeX format, with the usual command

pdflatex TryMyHyphenation


and look at the result: you’ll find that the word “axaxaxaaaxaxaxa” is not hyphenated.

Next, try compiling it with your new custom format: this can be done by means of the -fmt command-line option. That is, type

pdflatex -fmt pdflatexmyhyphen TryMyHyphenation


Two thing should now happen:

1. during the compilation, you should see the message

*** This is my home-made LaTeX format! ***


and also find it in the transcript file;

2. TeX should now be able to hyphenate the word “axaxaxaaaxaxaxa”.

Here is the output I get in the second run:

# Alternative method: Using fmtutil to replace the original format

Yesterday I hadn’t tested this method yet, so I didn’t dare recommend it. Contrary to the previous answer, this time we will not make a custom format by a different name, but we’ll override the pdflatex.fmt file itself with our custom version. Although it is not possible to do this from within the personal texmf tree, it can be done, under TeX Live’s supervision, from a different point of your home directory. It turns out that this solution is actually easier to carry out than the previous one; but replacing the (pdf)LaTeX format itself is something that not all users might feel comfortable with… (:-) (Of course, there are also a lot of good reasons for which even knowledgeable users might simply prefer to avoid doing so.)

So, let’s start again from our custom dumyhyph.tex file saved in a directory FOO/ of our choice (remember that, although the name and the location of the directory are arbitrary, the basename dumyhyph.tex must be used):

% It's a dummy file dumyhyph.tex created for testing purposes.
% This file is normally defined in language.dat et may be used by language
% styles such as french.sty to define a temporary language. B. Gaulle 23/10/91

\begingroup
\patterns{ % dummy patterns
.ach4
z4zy
% I add a pattern that does permit hyphenation:
aa5a
% (hyphenation will be possible only at places where at least three consecutive
% "a" characters occur).
}
\gdef\ParapaPonziPonziPo{*** This is a home-made TeX format! ***}
\def\typeout{\immediate\write17}
\obeyspaces
\typeout{****************************************************************}
\typeout{*   Custom hyphenation pattern file dumyhyph.tex' has been    *}
\typeout{****************************************************************}
\endgroup


As you can see, I’ve added a few banner lines, that will be displayed during the format-making process. Make FOO/ your current directory and issue one of the following commands:

• if you want to rebuild only the pdflatex.fmt format file, issue

mktexfmt pdflatex.fmt


(this is what I recommend, at least for testing purposes);

• if you want to rebuild all formats for the pdfTeX engine, issue

fmtutil --byengine pdftex


(are you sure that this is what you want?).

A lot of messages will flash on the terminal: one of them, displayed shortly before you get the shell prompt again, is important. It tells you where your custom format(s) has/have been installed, and it looks like this:

fmtutil: /home/mezzetti/.texmf-var/web2c/pdflatex.fmt installed.


Take note of this location! It’s system-dependent, and you might need it when you want to get rid of the custom format.

Assuming the location indicated above, you should also find a transcript file named

/home/mezzetti/.texmf-var/web2c/pdflatex.log


Open it: it should contain the following lines, more or less around line 400:

===========================================
Local configuration file hyphen.cfg used
===========================================
(/usr/local/texlive/2015/texmf-dist/tex/generic/babel/hyphen.cfg
File: hyphen.cfg 2016/02/24 3.9q Babel hyphens

(/usr/local/texlive/2015/texmf-dist/tex/generic/babel/switch.def
File: switch.def 2016/02/24 3.9q Babel switching mechanism
)
\l@english=\language0

(/usr/local/texlive/2015/texmf-dist/tex/generic/hyphen/hyphen.tex)
\l@usenglish=\language0
\l@USenglish=\language0
\l@american=\language0
\l@dumylang=\language1

(/Users/gustavo/Desktop/FOO/dumyhyph.tex
****************************************************************
*   Custom hyphenation pattern file dumyhyph.tex' has been    *
****************************************************************
)


This confirms that our custom hyphenation file was used (and, yes, it also shows that the system on which this example was generated is not very up-to-date…)

You are done. From now on, the format that incorporates your custom patterns will be used instead of the original one: no need to use any -fmt option, just compile as usual.

When you want to get rid of the custom format(s), go back to your note and remove anything under .../web2c/, including the directory .../web2c itself. For example, assuming the location shown above, you’d go

rm -rf /home/mezzetti/.texmf-var/web2c/


To show another example, if the message you got after running mktexfmt had been

mktexfmt [INFO]: /Users/gustavo/Library/texlive/2015/texmf-var/web2c/pdftex/pdflatex.fmt installed.


you would issue the following command

rm -rf /Users/gustavo/Library/texlive/2015/texmf-var/web2c/


to restore the distribution formats.

• I tried your first method. The command pdflatex -ini -etex -jobname pdflatexmyhyphen pdflatex.ini failed to produce a pdflatexmyhyphen.fmt file; it reports problems with file /usr/share/texmf-texlive/tex/generic/babel/hyphen.cfg (unmodified since 2008), it also could not find file /etc/texmf/hyphen.d/, but that hyphen.d is a directory, not a file. Is there a way of sending you the pdflatexmyhyphen.log file it produced? Aug 24, 2016 at 12:49
• I might have messed up things by formerly running update-language-dat --conf-dir ~/texmf/tex/generic/hyphen/ or update-language-dat --conf-dir /home/goswin/texmf/tex/generic/hyphen/, which I did not know how to undo. Aug 24, 2016 at 12:54
• @Goswin: Why the semicolon in /usr/share/texmf-texlive/tex/generic/‌​;babel/hyphen.cf‌​g?
– GuM
Aug 24, 2016 at 13:04
• @ Gustavo Mezzetti: I do not know; there is no semicolon in the file pdflatexmyhyphen.log. It was introduced by the stackexchange-software when I saved the comment; maybe an invisible character that became visible, it disappeared when I typed in the path by hand. Aug 24, 2016 at 16:41
• @Goswin: The “language” dumyhyph.tex is listed in the original language.dat file, and that’s why that particular name works “out of the box”. You may, of course, name your hyphenation file differently, or use several custom hyphenation files, but you need to add them to language.dat. I’ve never modified language.dat myself: in theory, I know how to do this in TeX Live, but maybe you’ve got the Debian version, that possibly uses a different method.
– GuM
Sep 4, 2016 at 13:55