2

I am using the following code to redefine a breve in order to work with a particular truetype font I must use (Elegant Garamond) and the particular piece of code generates an error (but still works) and it generates output on the typesetted document.

\documentclass[10pt,a4paper,openany]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[romanian]{babel}

\usepackage{eg}       %this is the definition for the font I use
\pdfmapfile{+eg.map}

\newcommand\chara{a}

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

\begin{document}        %begining here avoids one error that \catcode line below generates

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

text with ă character
\end{document}

Compiling the file gives me two errors:

! Missing number, treated as zero.
<to be read again> 
                   \protect 
l.17 \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.17 \catcode`\ă
                 =\active
You need to provide a definition with \DeclareInputText 
or \DeclareInputMath before using this key.

The output is an expected "text with ă character" but just before, on the first line, there is a string: "=,". As in the screencap:

enter image description here

Is there a way to supress it or to solve the errors I get?

I have read the suggested part in The TeXbook but I can't find the logic (well, I barely know TeX/LaTeX). Obviously my code is broken, but I can't find in what way or if there are some problems with my font...

  • 2
    As I commented on your previosu question, you can not use as a command name if you are using UTF8 encoding, use \abreve or some such name. – David Carlisle Mar 03 '17 at 13:38
  • http://tex.stackexchange.com/questions/356205/kerning-problems-for-a-composite-character#comment876813_356205 – David Carlisle Mar 03 '17 at 13:39

1 Answers1

4

You need a different structure to handle UTF-8 with pdftex (but see below for different solution):

\documentclass[10pt,a4paper,openany]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[romanian]{babel}

%\usepackage{eg}       %this is the definition for the font I use
%\pdfmapfile{+eg.map}

\newcommand\chara{a}

\makeatletter
\def\kernbrevea#1{\kern#1\dimexpr0.47em-\strip@pt\fontdimen1\font\dimexpr-0.2em\relax\relax}
\makeatother
\DeclareUnicodeCharacter{0103}{\raisebox{.0em}\u\kernbrevea{-}{\chara}}

\begin{document}

text with ă character
\end{document}

However the above is still really not the correct approach : it is tying the input encoding to a specific font encoding, and as you have seen breaks if the file is encoded as latin1 or latin2 rather than UTF8. Also it does not address the standard latex markup for the character, \u{a}

So better is just to declare \u{a} to be your raisebox construct. Then \u{a} will use your definition and ă expands to \u{a} so will automatically get the new definition and so neither the catcode tricks of the previous question nor \DeclareUnicodeCharacter are needed.

\documentclass[10pt,a4paper,openany]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[romanian]{babel}

%\usepackage{eg}       %this is the definition for the font I use
%\pdfmapfile{+eg.map}


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

%\DeclareTextComposite{\u}{T1}{a}{160}% T1 default
\DeclareTextCompositeCommand{\u}{T1}{a}{\raisebox{.0em}\u\kernbrevea{-}{a}}
\begin{document}

text with ă character and \u{a}
\end{document}
David Carlisle
  • 757,742
  • (I just commented out the eg code as I don't have the font, you can put that back) – David Carlisle Mar 03 '17 at 13:45
  • Thank you very much for your help, it works flawlessly, the second version of your answer, I mean. Since then I have managed to update some other hacks that I also had in there and, most importantly, I'm beginning to understand the logic, and that's a big step! Thanks again! On another topic, can you direct me where to get information about the \DeclareTextComopsiteComand kind of commands? I have searched the web only to find tangential references to them, not something more organised. I fear I would have to take a peak to the source code for TeX and that's too big for me right now... – Bogdan Agapie Mar 04 '17 at 11:26
  • 1
    @BogdanAgapie DeclareTextCompositeCommand is defined in the format so you could look at texdoc source2e or perhaps more usefully look at how T1 encoding is setup in the file t1enc.def – David Carlisle Mar 04 '17 at 11:36
  • Well, after a lot of tries I have reverted to the original version. Errors and all, but that version enables me to use the ă and all the other diacritics with the font I need while not messing with the same diacritics in the LaTeX's sansserif font I use for chapter and section title. Also, I have several other fine tuning settings I have made for a few more characters that have the wrong kerning information in the font and using \catcode seems to work, albeit with side-effects. Probably there are ways to solve all, but I must finish the job. Thanks for the help, won't go to waste though! – Bogdan Agapie Mar 06 '17 at 15:34
  • @BogdanAgapie getting stuff finished is always a good plan:-) I assume then that you have reverted to latin-2 encoding as setting the catcode of ă can not work at all in UTF-8 in pdftex. – David Carlisle Mar 06 '17 at 15:42
  • No, still using UTF-8 in pdftex. Somehow, without \catcode and the following line, no ă is typeset and every occurrence (several thousand) is reported as error; with those two lines, two errors are generated (the ones from OP) but all ă are there and are well displayed. Same for the rest: ș, ț and uppercase versions. Using Latin-2 encoding prevents me from using eg font at all, so four errors are manageable. On a side note, only defs for ă and ș generate errors; uppercase versions and ț, Ț are accepted... :-) Might be a bug in my favor? :) Who knows, but the book will be finished in time... – Bogdan Agapie Mar 06 '17 at 16:08
  • I'd look really closely at your output. If the file is utf-8 then to pdftex ă is two characters so it can not have a catcode and if you go \def ă{...} you redefine every character with the same first UTF-8 byte Ă will no longer work for example. – David Carlisle Mar 06 '17 at 16:29
  • I know this. Well, then I suppose the nicest solution would be to have pdflatex know that ă in my source means to put a composite character a with breve, then babel should know about the word with ă and hyphenate it, and have two different definitions for lower and upper case letters. Same with ș and ț. Well, with my (extremely) limited knowledge of TeX, I can't came up with an clean version for this. So... I improvise. The output will be paper, not a PDF file, so I don't care if there is no support for copy-paste... Anyway, Ă works well, I wouldn't use the trick otherwise. – Bogdan Agapie Mar 06 '17 at 16:58
  • And sorry for another comment, but there is more... :) The source code must remain as human readable as possible, as it is possible to have someone else operate possible modifications on the text and having ă replaced with a long stream of cryptic commands is not acceptable for someone with NO knowledge of latex. I must, therefore, keep the readability of the source code at maximum, that's why I redefined ? and ! to have extra space before, or \guillemotleft to have extra nonbreakable space after, so that in source would be minimum of typesetting commands. – Bogdan Agapie Mar 06 '17 at 17:02
  • OK, but it's my code that's handling the utf8 encoding in pdflatex that and my impression is that it can not possibly work as you describe. But I can not see your input or output so I just leave the warning and stop here. There are several things that could work and it may be that you are doing that and it is just mis-communication :-) – David Carlisle Mar 06 '17 at 17:02