Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Restated Problem and a Solution

The use of a times font using the package txfonts will cause tables to be improperly displayed (see below for an image) if a character such as ę,ą or a different character with an ogonek is used.

This has something to do with the procedure involved not being local, that is, having unwanted side effects elsewhere.

An effective way of keeping whatever is done local is by enclosing it in brackets {ę}. This can be generally invoked for any mention of the character in question by mapping ę to {ę}, a to {ą} and so on in the preamble by the following:

\DeclareUnicodeCharacter {281}{{ę}} % 281 is the decimal utf-8 code of ę
...

This will solve the problem for the whole document

A more general solution still that fixes the error introduced in the source file of txfonts is described below under the heading WORKAROUND. However, if you do not want to fiddle with the way the package is called (possibly because it is called in a stylesheet you do not want to change) redefining the characters is a good solution

Initial question

I am typesetting a multilingual document with pdflatex (MikTeX, all packages up to date). I need to use Times font, and, for the time being, I cannot switch to LuaLatex or XeLatex since I am in the final phase of typesetting a book with a class provided by my publisher and I would need to adjust my code in order to use these above.

Using Polish characters with txfonts causes the tables to crash:

\documentclass{article} 
\usepackage{txfonts}
%\usepackage{mathptmx}
\usepackage[polish, english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}       
\newcommand{\ee}{\selectlanguage{english}\fontencoding{T1}}
\newcommand{\pl}{\selectlanguage{polish}\fontencoding{T1}}
\begin{document}
\textbf{A minimal example using a times font}
As soon as I enter the Polish character \pl ę  \ee the tables crash 
(the lines of the table get printed onto each other).
\begin{table}\begin{center}\begin{tabular}{|l||l|l|}
\hline
type&n    &rel        \\
\hline
\hline
One line in the table &260& many  \\
Another line in the table      &792&49  \\
A third line in the table       &288&1  \\
\hline
\end{tabular}\end{center}\caption{A test table.}\end{table}
\end{document}

The alternative package mathptmx does not cause this problem; however, it does not provide the Greek characters I need. This is demonstrated in the following minimal example:

\documentclass{article} 
%\usepackage{mathptmx}
\usepackage{txfontsb}
\usepackage[polutonikogreek,polish, english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage[LGR,T1]{fontenc}       
\newcommand{\ee}{\selectlanguage{english}\fontencoding{T1}}
\newcommand{\grrk}{\selectlanguage{polutonikogreek}\fontencoding{LGR}}
\begin{document}
\textbf{A minimal example using a times font}
I need to  print polytonic Greek (and other special characters) using a 
times font (e.g. \grrk ἐᾶν \textbf{ἐᾶν})! \ee  
I use the \emph{txfonts} (or   \emph{txfontsb}) package,
the alternative \emph{mathptmx} cannot find the metric files (``Couldn't find `grtm.cfg'''). 
\end{document}

How can I use txfonts and still prevent the tables from crashing? I have also tried out txfontsb!

Update: I see now the has nothing to do with Polish, it's the diacritic in ę (the ogonek) that causes the problem. The same problem appears in the following code with an ogonek on an m:

    \documentclass{article} 
    \usepackage{txfonts}
    \usepackage[T1]{fontenc}       
    \begin{document}
    text with ogonek:        \k{m}  
    \begin{table}\begin{center}\begin{tabular}{|l||l|l|}
    \hline
    type&n    &rel        \\
    \hline
    \hline
    One line in the table &260& many  \\
    Another line &792&49  \\
    A third line in the table       &288&1  \\
    \hline
    \end{tabular}\end{center}\caption{A test table.}\end{table}
    \end{document}

If \k{m} is enclosed in brackets {\k{m}} the tables work fine. So it has something to do with locality and the way txfonts apply the ogonek.

share|improve this question
    
No, I don't think that redefining characters is a good solution. It will break kerning and hyphenation, for instance. –  egreg Dec 19 '11 at 13:31

2 Answers 2

up vote 3 down vote accepted

The shortest fix: use braces around ę:

\pl {ę} \ee

For longer text, you could use the otherlanguage environment instead of switching by \selectlanguage to Polish and back to English:

\begin{otherlanguage}{polish}
ę
\end{otherlanguage}

Before, with \pl ę \ee (\selectlanguage), for illustration:

Polish text and table, problem

Afterwards, with braces or otherlanguage:

Polish text and table, fixed

share|improve this answer
    
Thanks, that does work. However, this solution is extremely impractical. Normally, I don't even signal the change of language in any way, that is I write Polish characters as in Wałęsa without explicit switching. This worked fine with the old times package and with mathptmx. Is there any other way? What causes the tables to crash? –  Ruprecht von Waldenfels Dec 19 '11 at 11:02
    
@RuprechtvonWaldenfels: I added a shorter fix by braces, which limits whatever the ę locally causes. –  Stefan Kottwitz Dec 19 '11 at 11:07
    
Thanks! I see now it has nothing to do with Polish, it's the diacritic in ę (the ogonek) that causes the problem. The same problem appears in the following code with an ogonek on an m: –  Ruprecht von Waldenfels Dec 19 '11 at 11:14
    
I've edited the question accordingly. –  Ruprecht von Waldenfels Dec 19 '11 at 11:19
    
Now that the problem was reduced to the ogonek, I've found a workaround: I map the unicode characters ę, ą and so on to an explicit composition of e, a plus ogonek and put these into brackets. In other words, adding \DeclareUnicodeCharacter {281}{{\k{e}}} to the preamble will solve my problem for the whole document. Thanks for your help that got me on the right track! I'll edit the question accordingly. –  Ruprecht von Waldenfels Dec 19 '11 at 11:38

It's not a good idea to say \selectlanguage{<language>} in the middle of a paragraph, as this command does many things with unpredictable results in case of a page break and, as you experienced, also in other cases.

For short inserts in a different language, use

\foreignlanguage{polish}{ę}

while for longer passages you can choose between

\begin{otherlanguage*}{polish}
...
\end{otherlanguage*}

and

\begin{otherlanguage}{polish}
...
\end{otherlanguage}

The difference is that the former doesn't change the fixed words (the chapter's name and so on), while the latter does. Both change the settings for hyphenation and language shortcuts.

It's actually not necessary to write \foreignlanguage{polish}{<polish passage>}:

\newcommand{\pl}[1]{\foreignlanguage{polish}{#1}}

makes available the syntax \pl{polish passage}.

Workaround

There is a tragic error in txfonts.sty where \k is redefined in a wrong way: the \ooalign macro is not protected by braces and so, as soon as one uses a letter with an ogonek at the outer group level, the setting \lineskiplimit=-\maxdimen becomes global.

One can correct it with

\makeatletter
\AtBeginDocument{\let\T@n@@nc@d@ngM@cr@M@d\relax}
\makeatother
\usepackage{txfonts}

This will avoid the wrong redefinition, so no other trick is necessary, as the definition of \k will remain the correct one issued by the fontenc package. However, a better loading order would be

\usepackage[T1]{fontenc}       
\usepackage[utf8x]{inputenc}
\usepackage[polish,english]{babel}
\makeatletter
\AtBeginDocument{\let\T@n@@nc@d@ngM@cr@M@d\relax}
\makeatother
\usepackage{txfonts}

A possible cleaner solution might be to write a "corrected package", say fixtxfonts.sty that says

\ProvidesPackage{fixtxfonts}
\AtEndOfPackage{%
  \let\T@n@@nc@d@ngM@cr@M@d\relax
  \DeclareTextCommand{\k}{LY1}[1]{{\ooalign{\hidewidth\char7\crcr#1}}}%
}
\RequirePackage{txfonts}

and say \usepackage{fixtxfonts} instead of \usepackage{txfonts}

share|improve this answer
    
Thanks; however, I need to swith languages constantly, this is why I actually normally do not switch them explicitely or only wiht minimal tags. The T1 font encoding is most of the time good enough for me. It would be very cumbersome to edit the whole manuscript for language switches. –  Ruprecht von Waldenfels Dec 19 '11 at 11:22
    
@RuprechtvonWaldenfels An error made since a long time doesn't become good. Sorry. I don't see any advantage in writing english \pl polish \ee english instead of english \pl{polish} english. –  egreg Dec 19 '11 at 11:44
    
Of course you're right and I will keep this in mind in the future! However, I normally do not switch at all, that is, I write hallo cześć привет and so on. And being able to do this is very valuable to me. –  Ruprecht von Waldenfels Dec 19 '11 at 11:54
1  
@RuprechtvonWaldenfels This will give wrong hyphenations. –  egreg Dec 19 '11 at 12:00
1  
@RuprechtvonWaldenfels See edited message for a probably resolutive workaround. –  egreg Dec 19 '11 at 12:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.