# Kerning problems for a composite character

I am trying to typeset a book that uses the diacritics used in Romanian language. As I have to use a specific font, I had to "construct" the characters using something like that:

\newcommand\chara {a}
\newcommand\charA {A}
\makeatletter
\def\kernbrevea#1{\kern#1\dimexpr0.47em-\strip@pt\fontdimen1\font\dimexpr-0.2em\relax\relax}
\def\kernbreveA#1{\kern#1\dimexpr0.56em-\strip@pt\fontdimen1\font\dimexpr-0.34em\relax\relax}
\makeatother

\catcode\ă=\active
\def ă{\raisebox{.0em}\u\kernbrevea{-}{\chara}\kernbrevea{+}\kernbrevea{-}}

\catcode\Ă=\active
\def Ă{\raisebox{.24em}\u\kernbreveA{-}{\charA}\kernbreveA{+}\kernbreveA{-}}


The result is satisfactory. I managed to build support for using the truetype files I need (following various tutorials I had found floating around the net) and it seems to work ok, except for the situation when this letter ends up at the end of a line in an paragraph. Something like this:

I suspect that there is something about the code after the \def commands above but I have to admit I am a complete novice to LaTeX and I gave up trying to understand the syntax for the commands listed... I have taken them nearly unchanged from another examples and might very well be quite stupid, I have no idea. Can anyone help me with a solution to this problem?

I know I should be switching to another font that has no problems but unfortunately I have to use this specific variant of ElegantGaramond.

Thank you!

Later edit

Ok, so the two main problems were solved: using romanian diacritics with a broken (probably) font. LaTeX did its best and allowed me to show those.

But now I have an annoying problem. This is the code that I have isolated that has everything I am interested included:

\documentclass[10pt,a4paper,openany]{book}
\usepackage[utf8]{inputenc}

\usepackage[T1]{fontenc}
\usepackage[romanian]{babel}
\usepackage{pxfonts}

\usepackage{eg}
\pdfmapfile{+eg.map}

\begin{document}

\newcommand\chara{a}
\newcommand\charA{A}
\newcommand\chars{s}
\newcommand\charS{S}
\newcommand\chart{t}
\newcommand\charT{T}

\makeatletter
\def\kernbrevea#1{\kern#1\dimexpr0.47em-\strip@pt\fontdimen1\font\dimexpr-0.2em\relax\relax}
\def\kernbreveA#1{\kern#1\dimexpr0.56em-\strip@pt\fontdimen1\font\dimexpr-0.34em\relax\relax}
\makeatother

\catcodeă =\active
\def ă{\raisebox{.0em}\u\kernbrevea{-}{\chara}}

\catcodeĂ=\active
\def Ă{\raisebox{.24em}\u\kernbreveA{-}{\charA}\kernbreveA{+}\kernbreveA{-}}

\catcodeş=\active
\def ş{\c{\chars}}
\catcodeŞ=\active
\def Ş{\c{\charS}}
\catcodeţ=\active
\def ţ{\c{\chart}}
\catcodeŢ=\active
\def Ţ{\c{\charT}}

Some test text using romanian diacritics:

şŞţŢăĂîÎâÂ

Kerning: hăh măh xăx VĂV WĂW

\end{document}


This renders as in the image:

So the text looks good, BUT some unwanted stuff appears. Obviously, the twice appearing "=," is not intended... And ok, I can understand that something from the line "\catcode\ă=\active" is generating this, since in the logs I have this:

! Missing number, treated as zero.
\protect
l.26 \catcodeă
=\active
A number should have been here; I inserted 0'.
(If you can't figure out why I needed to see a number,
look up weird error' in the index to The TeXbook.)

! Package inputenc Error: Keyboard character used is undefined
(inputenc)                in inputencoding utf8'.

See the inputenc package documentation for explanation.
Type  H <return>  for immediate help.
...

l.26 \catcodeă
=\active
You need to provide a definition with \DeclareInputText
or \DeclareInputMath before using this key.

! Missing number, treated as zero.
\protect


and two similar errors are generated from the ș definition. What I don't understand is why the other definitions (apparently identical in form or syntax) aren't generating errors?

I've made a zip file all.zip available for 10 days from wetransfer that probably has all the files to reproduce the document, in case someone wants to replicate the problem. Most probably I am quite illiterate in LaTeX to understand where is the problem. All I can do is look perplexed in the code...

• The diacritic looks very much like a "breve". Is \u{a} and \u{A} not working for you -- or not appropriate for some reason? (I will admit to not being familiar with the particulars of the font called "Elegant Garamond".) – Mico Feb 28 '17 at 14:36
• What's the reason for adding two kerns that cancel each other? And what's the problem when you do \u{a}? – egreg Feb 28 '17 at 15:00
• You can not use a command such as \Ă in pdflatex if you are using ITF-8 encoding. but it is not clear why the standard inputenc commands are not sufficient – David Carlisle Feb 28 '17 at 15:01
• @DavidCarlisle I guess a different input encoding is used. – egreg Feb 28 '17 at 15:02
• Yes so it'll look like it works but then fail in interesting ways if the encoding is changed... – David Carlisle Feb 28 '17 at 15:25

The problem is that if a kern is immediately followed by glue (for instance a space) it becomes a feasible line break point and will disappear at the break together with the following glue.

However, in your case you have two kerns, so just the second one can be considered for a line break and the first one remains (which is a positive kern.

I can't understand the reason for two trailing kerns that cancel each other (except possibly when followed by glue).

Just remove them.

A different suggestion for your macros, assuming that \u{a} and \u{A} don't produce the correct output:

\documentclass{article}
\usepackage[latin2]{inputenc}

\leavevmode\vbox{\offinterlineskip
\ialign{\hfil##\hfil\cr\u{}\cr\noalign{\vskip-1ex}#1\cr}%
}%
}

\catcodeă=\active \protected\def ă{\abreve}
\catcodeĂ=\active \protected\def Ă{\Abreve}
\lccodeĂ=ă
\uccodeă=Ă

\begin{document}

destinată să

\MakeUppercase{destinată să}

\end{document}


You can more freely adjust the spacing and the positioning of the accent, maybe branching differently the cases of ă and Ă.

If you use utf8 as encoding, the approach should be a bit different:

\documentclass[10pt,a4paper,openany]{book}
\usepackage[utf8]{inputenc}

\usepackage[T1]{fontenc}
\usepackage[romanian]{babel}
\usepackage{pxfonts}
\usepackage{newunicodechar}
\usepackage{etoolbox}

\usepackage{eg}
\pdfmapfile{+eg.map}

\makeatletter
\def\kernbrevea#1{\kern#1\dimexpr0.47em-\strip@pt\fontdimen1\font\dimexpr-0.2em\relax\relax}
\def\kernbreveA#1{\kern#1\dimexpr0.56em-\strip@pt\fontdimen1\font\dimexpr-0.34em\relax\relax}
\makeatother

\newunicodechar{ă}{\raisebox{.0em}\u\kernbrevea{-}{a}}
\newunicodechar{Ă}{\raisebox{.24em}\u\kernbreveA{-}{A}}

\begin{document}

Some test text using romanian diacritics:

şŞţŢăĂîÎâÂ

Kerning: hăh măh xăx VĂV WĂW

\MakeUppercase{ă}

\end{document}


No need to give definitions for the other characters.

• It works! Well, mostly. :) The first problem is that the italic version of the ttf used seems to have the breve character in a different position, so while the normal ă looks ok, the italic one has the breve too low and too to the left. Could you tell me how to remedy this situation? I will add a post/reply in order to put some screen captures to show how this might be a problem. – Bogdan Agapie Feb 28 '17 at 17:13
• You were right, I have removed \kernbrevea{+}\kernbrevea{-} from the \def line and the problem was solved. Completely. Thank you very much for your help! – Bogdan Agapie Feb 28 '17 at 18:05