# How to hyphenate Portuguese in plain TeX?

I'd like to use plain TeX in Portuguese, but I don't know how to hyphenate in this language, or in any other language than English. What do I have to do?

-
 I'm no expert in plain TeX, but maybe you will find something here (especially the "Tabelas de Hifenação"): gentzen.mat.uc.pt/~gutpt/LaTeXPortugues/latexportugues.html – Turion Jul 4 '11 at 14:49 Thank you, but that was for LaTeX. The problem is with plain TeX. I know there's a command \language in plain TeX to set the language by the language number, but I suspect it will simply not work without installing somewhere the hyphenation patterns. And I do not know how to do that. – Frederico Lopes Jul 4 '11 at 15:36 Could it be that you are using MikTeX portable, which, judging from its size, perhaps wouldn't include support for portuguese? – morbusg Jul 14 '11 at 18:38

With XeTeX it should be as simple as:

\uselanguage{portuguese}
\font\test="Helvetica"
\hsize=1cm
\test
Tabelas de Hifenação
\bye


But if for some reason the command \uselanguage isn't available for you, you could try \language=18.

-
 I'm using MikTeX 2.9 and I tried >xetex myfile.tex with your code but it didn't work. xetex is in the system, but it didn't work. – Frederico Lopes Jul 4 '11 at 18:43 It's the same with pdftex – egreg Jul 4 '11 at 19:13 @egreg: the same, as in "doesn't work", or the same, as in "you can input utf-8 with pdftex"? At any rate, the example runs fine for me (basictex-2010 on osx); the "Hifenação" get hyphenated "Hife-etc.". – morbusg Jul 4 '11 at 19:38 No, you can't input utf-8 with pdftex without defining the necessary environment; but that's not what the OP was asking. – egreg Jul 4 '11 at 19:42 @egreg: Sorry to bug you but I'm not clear on whether it didn't work for you, or..? – morbusg Jul 4 '11 at 20:01

I can propose a procedure for XeTeX; there is some that can be done also for pdfTeX, but it needs some time.

Find in your TeX distribution the file called hylang.tex and copy it into a working directory. Modify it to be

%%% This is hylang.tex (version 1.0), where language definitions
%%% actually occur. The first one should always be
%%% American English, for compatibility with plain TeX.
%%%
%%% Users can modify this file in order to define the
%%% languages they need.
%%%
%%% Every language definition should be followed by a
%%% \refinelanguage command where conventions specific to
%%% the language are set; users should at least provide
%%% the left and right hyphenation minima using
%%% \hyphenmins{<left>}{<right>}
%%%
%%% In the third argument one puts what has to be done
%%% when activating the language; in the fourth argument
%%% what needs to be undone.

\input unicode-letters

%%% US English must always come first
\definebaselanguage{en}{US}{hyphen} %%% <--- don't modify
\refinelanguage{en}{US}{\hyphenmins{2}{3}}{}

%%% Portuguese
\refinelanguage{pt}{PT}{\hyphenmins{2}{3}}{}

\definedialect{pt}{BR}{pt}{PT}
\refinedialect{pt}{BR}{\hyphenmins{2}{3}}{}

%%% Add other languages if needed
%%%
%%% The arguments to \definelanguage are:
%%% #1: the language code; it is an arbitrary string, use the
%%%     ISO two-letter language code for uniformity, or nde' for
%%%     new orthography German
%%% #2: the nation code; use the uppercase ISO two-letter code
%%% #3: the file with hyphenation patterns
%%%
%%% The arguments to \refinelanguage and \refinedialect are:
%%% #1 and #2: a pair defined through \definelanguage or \definedialect
%%% #3: commands to be executed when entering the language
%%% #4: commands to be undone when entering a new language
%%%
% \definelanguage{xx}{YY}{xxhyph}
% \refinelanguage{xx}{YY}{<something>}{<something>}
%
% \definedialect{aa}{BB}{xx}{XX}
% \refinedialect{aa}{BB}{<something>}{<something>}

% At last the fallback, a language with no patterns
\definelanguage{zz}{ZZ}{zerohyph}
% \refinelanguage{zz}{ZZ}{}{} % no need to set conventions

%%% Aliases

\endinput


Now call the initialization program

xetex -ini '*hyplain'

This will create a new format file hyplain.fmt and you can test it by running

xetex '&hyplain test'

where test.tex is

\font\standard="TeX Gyre Termes/mapping=tex-text"
\standard

\parindent=0pt

\selectlanguage{pt}{PT}

\hsize=2pt

\hskip0pt
Tabelas de Hifenação

\hskip0pt
Lisboa possui inúmeras atracções turísticas. A baixa pombalina, Belém,
Chiado ou Bairro Alto, são zonas onde afluem milhares de turistas e
visitantes anualmente. Duas agências europeias têm sede em Lisboa: o
Observatório Europeu da Droga e da Toxicodependência e a Agência
Europeia de Segurança Marítima, ambas com projectos de novas sedes à
beira rio. A Comunidade dos Países de Língua Portuguesa encontra-se

\bye


The format file can be moved in a suitable directory, consult the manual for your distribution in order to see where and how.

Caveat: I wrote the "hyplain" system.

-
It's difficult to answer to "didn't work". – egreg Aug 7 '11 at 20:46

In Plain TeX, just set a non-used language number and then input the hyphenation patterns for Portuguese — a TeX file available in every distribution, like this:

\language=7
\input pt8hyph.tex
\def\portugues{\language=7\relax}


Patterns are associated to language number, switch the number to change hyphenation rules, or create some definitions to handle this. It works with UTF-8!

You can get this file in http://www.ctan.org/tex-archive/language/portuguese Thanks to Pedro J. de Rezende (rezende@dcc.unicamp.br) and J.Joao Dias Almeida (jj@di.uminho.pt) for baking it.

-
This doesn't work in a normal document; patterns can be loaded only in iniTeX, that is at format creation. – egreg Jul 15 '11 at 7:59
You're right, it should be used when creating a format, I forgot to mention. Example: run pdftex -ini myformat.tex where myformat.tex is a file with commands like \input plain \language=7 \input pt8hyph.tex \dump then use the format created: pdftex -fmt myformat` on our manuscript. – Caio Lopes Jul 16 '11 at 3:22