I am about to make the paradigm-shift from the traditional way of hard-coding fonts with diacritical marks on top of them to simply using utf8. What surprised me, however, that the rendering of the fonts are quite different.

\documentclass[12pt]{article}
%\usepackage[utf8]{inputenc}
%\usepackage[T1]{fontenc}
\begin{document}
A\'A\AA E\'EI\'IO\'O\"O\H{O}U\'U\"U\H{U}
\end{document}

Here is how the good old way is rendered: oldschool fonts

And here is how utf8 looks like (after removing the comments from above): enter image description here

Notice that in the utf8 font the top diacritical marks are pushed downwards, and the letter \AA "A with a ring" seems to be rendered as "A with an ellipsoid". For my eyes which got used to the first variant, the second way of rendering is just unacceptable. Is there a way to fine-tune the utf8 family, to render the diacritical marks exactly the same way as above? If I remove the line \usepackage[T1]{fontenc} then the rendering seems fine. But then I cannot copy-paste from the pdf, hyphenation is not working, etc.


Related: Why should I use \usepackage[T1]{fontenc}? and fontenc vs inputenc.

  • 6
    utf8 has nothing to do with it. T1 encoding changes the font and so the glyphs, now in most cases a real glyph and not a constructed glyph will be used. If you don't like it you will have to redesign the glyphs or use another font. – Ulrike Fischer May 24 '16 at 9:55
  • Yes, I am beginning to understand that fontenc and inputenc are for two entirely different things. Is it possible to redesign the glyphs based on the ordinary rendering above? – Matsmath May 24 '16 at 9:57
  • 3
    Sure. There are tools like fontforge and other. But font design is hard work and needs some skill. – Ulrike Fischer May 24 '16 at 9:59
  • Some of the considerations at tex.stackexchange.com/q/258297/7883 are relevant here. – Thérèse May 27 '16 at 0:13
up vote 10 down vote accepted
+50

Complex solution

This solution skips loading fontenc and uses the package newunicodechar to redefine the accented characters, in order to preserve the original accents while retaining some hyphenation. The trick used is to split the word while shortening the interword space to nothing.

As I said, some (but not all) hyphenation is preserved, as well as ligatures. Copying from the pdf should work like just not using fontenc (and for me (Evince on Ubuntu) that works just fine). Kerning does not work for the accented letters. Also, the code fails under various circumstances (e.g. in section titles and captions), though in those cases you can use the old command like \"O etc.

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage{newunicodechar}

\newcommand{\DeclareAccentChar}[2]{%
    \newunicodechar{#1}{%
        \bgroup
        \newdimen\originalspacelength%
        \newdimen\originalspacestretch%
        \newdimen\originalspaceshrink%
        \originalspacelength=\fontdimen2\font%
        \originalspacestretch=\fontdimen3\font%
        \originalspaceshrink=\fontdimen4\font%
        \fontdimen2\font=0pt%
        \fontdimen3\font=0pt%
        \fontdimen4\font=0pt%
        #2%
        \nolinebreak\space
        \fontdimen2\font=\originalspacelength
        \fontdimen3\font=\originalspacestretch
        \fontdimen4\font=\originalspaceshrink
        \egroup}}

\DeclareAccentChar{Á}{\'A}
\DeclareAccentChar{Å}{\AA}
\DeclareAccentChar{É}{\'E}
\DeclareAccentChar{Í}{\'I}
\DeclareAccentChar{Ó}{\'O}
\DeclareAccentChar{Ö}{\"O}
\DeclareAccentChar{Ő}{\H{O}}
\DeclareAccentChar{Ú}{\'U}
\DeclareAccentChar{Ü}{\"U}
\DeclareAccentChar{Ű}{\H{U}}
\DeclareAccentChar{ö}{\"o}
\DeclareAccentChar{é}{\'e}

\begin{document}


AÁÅEÉIÍOÓÖŐUÚÜŰ

\parbox{0pt}{\null\ cooperation}
\hspace{3em}
\parbox{0pt}{\null\ coöperation}
\hspace{4em}
\parbox{0pt}{\null\ co\-öp\-er\-a\-tion}

\bigskip
\parbox{3em}{VAV VÅV}
soufflé

\end{document}

Computer Modern with accents

Since the accented characters are defined as regular LaTeX expressions, it might be possible to edit the code to improve copying from the pdf. Also, it might be possible to get more hyphenation points by locally relaxing TeX's hyphenation limits.

If you prefer the accents of Steven B. Segletes' answer, just add the following code from that answer together with definitions for the lowercase characters (note that lowercase i needs to be defined as \DeclareAccentChar{í}{\'\i}) to get the same output as his (except that Å is taken from Computer Modern instead of Latin Modern) while retaining some hyphenation.

\usepackage{stackengine,scalerel,graphicx}
\renewcommand\'[1]{\stackengine{.15ex}{#1}{%
  \scalebox{1.2}[.75]{\scaleto{\scriptscriptstyle\prime}{.6ex}}}{O}{c}{F}{T}{S}}
\renewcommand\H[1]{\stackengine{.15ex}{#1}{%
  \scalebox{1.2}[.75]{\scaleto{\scriptscriptstyle\prime\kern-.03em\prime}{.6ex}}}{O}{c}{F}{T}{S}}
\renewcommand\"[1]{\stackengine{.2ex}{#1}{%
  .\kern-.1em.}{O}{c}{F}{T}{S}}

Correct kerning

This code adds an optional argument to get correct kerning, but it really messes with copying text. It will fail if the width of the accented character doesn't match the width of the unaccented character. Also, when viewing the pdf the character may seem thicker than usual, though it should print fine (I hope).

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage{newunicodechar}

\newlength\charwidth%
\newcommand{\DeclareAccentChar}[3][]{%
    \newunicodechar{#2}{%
        #1%
        \settowidth{\charwidth}{#1}%
        \kern-\charwidth
        \newdimen\originalspacelength
        \newdimen\originalspacestretch
        \newdimen\originalspaceshrink
        \originalspacelength=\fontdimen2\font
        \originalspacestretch=\fontdimen3\font
        \originalspaceshrink=\fontdimen4\font
        \fontdimen2\font=0pt%
        \fontdimen3\font=0pt%
        \fontdimen4\font=0pt%
        #3%
        \kern-\charwidth%
        \nolinebreak\space
        \fontdimen2\font=\originalspacelength
        \fontdimen3\font=\originalspacestretch
        \fontdimen4\font=\originalspaceshrink
        #1}}

\DeclareAccentChar{Á}{\'A}
\DeclareAccentChar[A]{Å}{\AA}

\begin{document}

\parbox{3em}{VAV VÁV}
\parbox{3em}{VAV VÅV}

\end{document}

Example showcasing different kerning


Simpler solution

You can \usepackage{lmodern} to get a version somewhat in between. In particular, the ring on Å is a circle (though somewhat thicker than the original). The accents are less slanted as well, especially for Ő and Ű.

With this method kerning, hyphenation and copying all works fine. Unless you really want the original accents or prefer cm-super, this is the way to go.

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\begin{document}
A\'A\AA E\'EI\'IO\'O\"O\H{O}U\'U\"U\H{U}
\end{document}

Latin Modern with accents

Further reading: Latin Modern vs cm-super?

  • Well, this certainly looks something different. The double acutes and the \aa looks fine now. But the double dots are still too close to the round top of the letters O and U, and what is even more unpleasant is that the (single) acute accents are kind of shallower. I know that this is a widely used font, but by looking at this, I would seriously call the rendering of the accents inconsistent. – Matsmath May 24 '16 at 10:50
  • 2
    As a native swedish speaker I would say that the Ö in latin modern is better than the original, though cm-super (fontenc without lmodern) is best. – Jonas Granholm May 24 '16 at 11:12
  • Regarding the acutes: Note that the original font doesn't have consistent slant either. There is tighter space when fitting two acutes over the letter, so that probably why it's different. A casual glance shows that different typefaces does this differently; e.g. Adobe Garamond has even more pronounced difference between Ó and Ő. – Jonas Granholm May 24 '16 at 11:19
  • Yes, it looks apparent in the capital letters. However, the accents in the lowercase letters ó and ő looks to me pretty much the same. This might be a "trend" or "thing" in typography. – Matsmath May 24 '16 at 11:25
  • Thank you for improving your answer. Not that it is super-important, but do I understand correctly that because of the word-splitting trick I lose some of the ligatures? – Matsmath May 26 '16 at 19:32

One can use lmodern, but redefine the functions \', \H, and \", though that may have some danger associated with it. As wipet points out, this approach breaks hyphenation(*), which in itself is enough to recommend against its use.

(*) Based on recent conversation with egreg at Words before rules are not divided, adding \nobreak\hspace{0pt} to the end of my stackengine diacritic redefinitions will allow fragment hyphenation in the text that follows the diacritic. Of course, manual hyphenation can always be added.

\documentclass[12pt]{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern,stackengine,scalerel,graphicx}
\renewcommand\'[1]{\stackengine{.15ex}{#1}{%
  \scalebox{1}[.75]{\scaleto{\scriptscriptstyle\prime}{.6ex}}}{O}{c}{F}{F}{S}%
  \nobreak\hspace{0pt}}
\renewcommand\H[1]{\stackengine{.15ex}{#1}{%
  \scalebox{1}[.75]{\scaleto{\scriptscriptstyle\prime\prime}{.6ex}}}{O}{c}{F}{F}{S}%
  \nobreak\hspace{0pt}}
\renewcommand\"[1]{\stackengine{.2ex}{#1}{%
  .\kern-.1em.}{O}{c}{F}{F}{S}\nobreak\hspace{0pt}}
\begin{document}
A\'A\AA E\'EI\'IO\'O\"O\H{O}U\'U\"U\H{U}

a\'a\aa e\'ei\'{\char"019}o\'o\"o\H{o}u\'u\"u\H{u}

\smallskip\tiny
A\'A\AA E\'EI\'IO\'O\"O\H{O}U\'U\"U\H{U}

\parbox{0pt}{\null\ cooperation}

\parbox{0pt}{\null\ co\"operation}

\parbox{0pt}{\null\ co\-\"op\-er\-a\-tion}
\end{document}

enter image description here


At the OP's request, I make the primes thicker horizontally (by stretching them 20% horizontally)...but of course that comes at the price of making them slightly more slanted. I have also reduced the distance slightly between the double accents of \H.

\documentclass[12pt]{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{stackengine,scalerel,graphicx}
\renewcommand\'[1]{\stackengine{.15ex}{#1}{%
  \scalebox{1.2}[.75]{\scaleto{\scriptscriptstyle\prime}{.6ex}}}{O}{c}{F}{T}{S}%
  \nobreak\hspace{0pt}}
\renewcommand\H[1]{\stackengine{.15ex}{#1}{%
  \scalebox{1.2}[.75]{\scaleto{\scriptscriptstyle\prime\kern-.03em\prime}{.6ex}}}{O}{c}{F}{T}{S}%
  \nobreak\hspace{0pt}}
\renewcommand\"[1]{\stackengine{.2ex}{#1}{%
  .\kern-.1em.}{O}{c}{F}{T}{S}\nobreak\hspace{0pt}}
\begin{document}
A\'A\AA E\'EI\'IO\'O\"O\H{O}U\'U\"U\H{U}

a\'a\aa e\'ei\'{\char"019}o\'o\"o\H{o}u\'u\"u\H{u}

\smallskip\tiny
A\'A\AA E\'EI\'IO\'O\"O\H{O}U\'U\"U\H{U}
\end{document}

enter image description here

  • 1
    Oh wait, are you suggesting here to continue using the good old fashioned escape characters to type text into my editor? Then there is no point at all in using \usepackage[utf8]{inputenc}. – Matsmath May 24 '16 at 11:28
  • @Matsmath You are right, and I have just removed the vestigial inputenc from my code. I am proposing using the old escape-character entry format, but redefining the diacritics to suit your font expectations. – Steven B. Segletes May 24 '16 at 11:33
  • In that case -- although I try not to look greedy -- could you make the acute accents just a slightly bit more thicker? They are significantly thinner than the (single or double) dots, and they look inconsistent. I am speculating here, but can I typeset those boldface? – Matsmath May 24 '16 at 11:40
  • 3
    This solution does not support the hyphenation of words and the copying texts from PDF. So, don't use it. If you disagree with accents of used font, make your personal copy of such font and use fontforge to correct the accents. But with knowledge that original fonts were made by professionals... – wipet May 24 '16 at 13:08
  • 1
    @Matsmath Please see my revision, in which egreg schooled me on how post-diacritic fragment hyphenation can be restored. – Steven B. Segletes Jun 3 '16 at 17:53

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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