Faking characters

From Wiki
Revision as of 13:25, 9 August 2020 by Taco (talk | contribs) (Text replacement - "<cmd>" to "{{cmd|")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

TODO: Perhaps give another title to this page, perhaps accented characters (See: To-Do List)


In TeX you can only access 256 glyphs at a time (With XeTeX and LuaTeX, it's over, thanks to UTF-8 support). Well, but even if you could access more of them, a glyph or two that you need may be absent in your favourite font.

Choosing the proper encoding

First of all: make sure that you are using the proper encoding and the proper regime (see slso Encodings and Regimes - Old Content). Most problems can already be solved by deciding for the proper encoding (or by making one by your own).


TODO: Describe where to check for it, perhaps write a wiki page for every encoding. (See: To-Do List)


You have to be aware that a word with faked glyphs cannot be hyphenated and the the resulting PDF won't be fully searchable either.


Using (already defined) named glyphs

If you use texnansi encoding, US keyboard and any Western European regime (ISO latin1 for example), there are not so many accented characters accesible by your keyboard and available in the regime and encoding you use.

If you want to get 'č' for example, the best way is simply to type

\ccaron

The glyph will be faked (composed of c and a caron), but it looks OK in most cases.

(If you need a lot of non-standard accented characters, texnansi, the default, may not be the best choice. Consider using the ec or any other encoding - see Encodings and Regimes - Old Content for more info.)

Composing characters

Simple composed characters

Suppose that (for whatever reason) you want to have a letter b with cedilla. As far as I know it's not used in any language and it's also not present in Unicode, so it would be unfair from you to expect to find it in any major font.

No reason for panic! It's as simple as:

\startencoding[default] % not really needed, but it's cleaner that way
    \definecharacter bcedilla {\buildtextcedilla b}
\stopencoding

And the next time you type

a\bcedilla c

you'll get a nice

Take a look at enco-def.tex to see how other characters were defined.

The most common accents from which you can compose characters are:

  • textacute
  • textbottomdot
  • textbreve
  • textcaron
  • textcedilla
  • textcircumflex
  • textdiaeresis
  • textdotaccent
  • textgrave
  • texthungarumlaut
  • textmacron
  • textogonek
  • textring
  • texttilde

However, some of them may be missing in the encoding you use, so make sure that the accent you want is available in the encoding first.


TODO: Provide a more comprehensive overview and more complex examples (See: To-Do List)


Defining a shortcut


TODO: enco-acc.tex (See: To-Do List)


Drawing characters

Adding strokes or other minor fixes

đ/Đ (U+0110/0111, "latin small/capital letter d with stroke") are glyphs present in very few encodings. On the other hand, only a straight line has to be drawn in order to fake the glyph. Although it is difficult to position this line (stroke) properly for a general case and despite being far from optimal, it can be sometimes useful to have such a little hack. Here's an example of how \dstroke and \Dstroke were faked:


TODO: Something goes here. (See: To-Do List)



Drawing with metafun


TODO: This is probably also possible. (Yes, it is; see the "verbatim end-of-line character" page for an example. --Brooks (See: To-Do List)


Cropping existing characters


TODO: How to use \crop (See: To-Do List)


Rotating/mirorring characters


TODO: Comments about the following code and some more examples. (See: To-Do List)


\starttext

\unexpanded\def\topaccent#1#2#3#4#5% down right slantcorrection accent char
 {\dontleavehmode
  \bgroup
    \setbox0\hbox{#4}%
    \setbox2\hbox{#5}%
    \hbox to \wd2 \bgroup
       \hss\copy2\hss
       \hskip-\wd2
       \hss\hskip#2\wd0\hskip-#3\fontdimen1\font\raise#1\hbox{#4}\hss
    \egroup
  \egroup}

\def\buildtextgrave{\topaccent{0pt}{0}{15}{\textgrave}}

\startencoding[default]

\definecharacter schwa      {\hbox{\rotate[rotation=180,location=high]{\hbox{e}}}}
\definecharacter schwagrave {\buildtextgrave\schwa}

\stopencoding 

Making your own encoding

Latin Modern for example happens to have over 600 glyphs, so it may be that your favourite glyph (such as udoublegrave) is already there, but you can't access it using standard encodings. In this case you can write your own encoding and support for it. This way takes some more effort and skills than all of the above mentioned solutions and it also takes additional effort if you want to compile the document on another computer. But unless you are using XeTeX, Aleph, ... or any other TeX system which got rid of the 256-glyphs-limit, this is the only proper way if you're opting for high quality.


TODO: Something goes here. (See: To-Do List)