7

I'm using OT1 font encoding, but I would like to use T1 font encoding for glyphs that don't exist in OT1. To do that, I'm redefining the typical T1 commands so that they automatically choose a T1 encoding. With the commands for accented letters, however, like \'e for é, using \newcommand{\'e} won't work because \' is already defined, but I can't use \renewcommand{\'e} either, since the full sequence \'e is not already defined.

Suggestions?

\documentclass{article}
\usepackage[T1, OT1]{fontenc}
%\newcommand{\'e}{\fontencoding{T1}\selectfont{\symbol{233}}} <- gives 'Command \' already defined' error
%\renewcommand{\'e}{\fontencoding{T1}\selectfont{\symbol{233}}} <- gives '\'eundefined' error
\begin{document}
\'e
\end{document}

EDIT:

Given all the comments about the OT1 vs. T1 encoding, here's the contents of the OT1 and T1 fonts for libertine. One can see here that the OT1 font has some ligatures the T1 font doesn't have:

\documentclass{article}
\usepackage{fonttable}
\begin{document}
\fonttable{LinLibertineT-lf-ot1} % OT1 encoding
\fonttable{LinLibertineT-lf-t1} % T1 encoding
\end{document}

enter image description here enter image description here

Sverre
  • 20,729
  • I'm confused by the aim here: LaTeX gives you a combined accent and e in OT1 here already, while if you want to have a single glyph, you can just use T1 generally. What is the reason for wanting to use OT1/T1 in this way? – Joseph Wright Sep 06 '13 at 10:20
  • This has no advantage, other than, perhaps, getting a sligthly better output; but you'll be mixing different fonts, so hyphenation will still not be possible. – egreg Sep 06 '13 at 10:21
  • @JosephWright: My reasons for wanting to use OT1 generally are explained here: http://tex.stackexchange.com/questions/130541/temporarily-change-font-encoding-with-fontenc. In short, OT1 has some glyphs T1 doesn't have, and T1 has some glyphs OT1 doesn't have. The OT1 combination of accent+e is ugly in the libertine font, so I want to use the T1 non-combined glyph. – Sverre Sep 06 '13 at 10:22
  • @Sverre Why don't you use T1 and forget about all the rest? – egreg Sep 06 '13 at 10:25
  • @egreg: Because then I lose some of the OT1 glyphs I want, which in the libertine font includes some nice ligatures missing from T1. – Sverre Sep 06 '13 at 10:26
  • @Sverre I'd say the right solution is to track down and fix what is up with libertine in this case, then. Really OT1 is only there for 'stability' reasons. – Joseph Wright Sep 06 '13 at 10:26
  • @JosephWright: I'm not sure what you mean. The libertine OT1 font has some ligatures the T1 font doesn't have. There's nothing I can do to "fix" that. It's just a fact about the font package. – Sverre Sep 06 '13 at 10:28
  • On the problem as posed, \'e is a command followed by a letter. As such, you'll need to redefine \' with knowledge of which letters it should fork for. Can you give us a list of the desired ones? – Joseph Wright Sep 06 '13 at 10:28
  • @Sverre The font sources must have the correct ligatures, so something is up with converting them to TeX format. That should get fixed. – Joseph Wright Sep 06 '13 at 10:29
  • @JosephWright Right now I can think of é, ó, ä, and ö ... – Sverre Sep 06 '13 at 10:30
  • 1
    @JosephWright: The main difference between OT1 and T1 is that T1 is full: on all 256 positions there is a glyph. In OT1 there are 128 "free" position which fonts can use for special glyphs/special effects. – Ulrike Fischer Sep 06 '13 at 10:46

1 Answers1

6

You can, but wouldn't it be simpler to switch to the T1 encoding?

\documentclass{article}
\usepackage[T1,OT1]{fontenc}
\usepackage{libertine}

\DeclareTextCompositeCommand{\'}{OT1}{e}{{\fontencoding{T1}\selectfont\'e}}

\begin{document}

a\accent19 ei % the original one

a\'ei

\end{document}

enter image description here

You can easily extend to all desired combinations using the same pattern. Note that you can even use \'e in the definition, since the encoding will already be T1 in the group, so the combination \'e will use the relative definition.

egreg
  • 1,121,712
  • @Sverre The switch to T1 must be local, therefore the additional pair of braces. Notice that I simplified the definition, so you don't even have to hunt through the table to find code points. – egreg Sep 06 '13 at 10:43
  • I see. I always enclose my macros (e.g. {\'e}) within brackets anyway, so the T1 encoding will be local. But I see that if I don't do that, it'll remain T1. – Sverre Sep 06 '13 at 10:52
  • The reason I went through the table to find the code points was that a redefinition such as \renewcommand{\aa}{\fontencoding{T1}\selectfont{\aa}} didn't work. I needed to do \renewcommand{\aa}{\fontencoding{T1}\selectfont{\symbol{229}}}. – Sverre Sep 06 '13 at 10:55
  • @Sverre Of course you can't use \aa in the definition of \aa; however, \DeclareTextCompositeCommand{\'}{OT1}{e}{...} doesn't define a \'e command, so using \'e in the body is possible, as long as the encoding is set to a different one than in the second argument. – egreg Sep 06 '13 at 10:58