Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am making a document with the Josefin Sans font in LaTeX (using XeLaTeX). However, a pair of symbols I need (Žž) is missing there; I get just an empty space in PDF. I have no idea at all about fonts, but decided to try it anyway since I really need it. I took the Type light 3.2 font editor, found the missing glyphs (017D and 017E), copy-and-pasted there the corresponding Z and z glyphs, and added the vertically flipped circumflexes from other glyphs. In OpenOffice Writer, the trick works. (Character spacing is screwed up, but I can live with it: I need these symbols just a couple of times in my document, so I can manually shift them in TeX.) However in TeX the symbol is still not typeset---I receive empty space.

I believe what I am doing is not the right way to go, but I really need it. Could anyone explain why XeLaTeX does not typeset the new symbol and if there is a better solution please?

My tex-code:

\documentclass{article}
\usepackage{fontspec}
\setsansfont{Josefin Sans}
\begin{document}
Žž{\textsf{ZzŽžZz}
\end{document}

The font files are available here.

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

This is admittedly complicated, but has the advantage that the input is the plain character.

\documentclass{article}
\usepackage{graphicx,newunicodechar}

\usepackage{fontspec}
\setsansfont{Josefin Sans}

\makeatletter
%% flip the caron
\def\fakehacekchar{\smash{\raisebox{\depth}{\scalebox{1}[-1]{\char"5E}}}}
%% define a "fake accent command"
\def\fakehacek#1{%
  \leavevmode\vbox{\baselineskip\z@skip \lineskip\z@skip
    \ialign{\hfil##\hfil\cr\fakehacekchar\cr#1\cr}}}
%% check if we have to use the fake háček
\ExplSyntaxOn
\cs_new_protected:Npn \makefakehacek #1 #2
 {
  \tl_if_in:VnTF \f@family {JosefinSans} {\fakehacek{#1}} { #2 }
 }
\cs_generate_variant:Nn \tl_if_in:nnTF { V }
\ExplSyntaxOff
\makeatother

\newunicodechar{Ž}{\makefakehacek{Z}{Ž}}
\newunicodechar{ž}{\makefakehacek{z}{ž}}

\begin{document}
Žž\textsf{ZzŽžZz}
\end{document}

If I had the choice, Josefine Sans wouldn't be in my book. :)

enter image description here

With a change to \fakehacekchar it may be more appealing: the scale factors in the x and y directions are different:

\def\fakehacekchar{\smash{\raisebox{\depth}{\scalebox{1.2}[-.8]{\char"5E}}}}

Here's the result:

enter image description here


How to get the fake háček:

  1. I flip vertically a caron: \scalebox{1}[-1}{\char"5E}

  2. The above operation will send the caron deep down the baseline, so I raise it to sit on the baseline: \raise{\depth}{...}

  3. Finally I make its dimensions zero, so that it would not influence the typesetting decisions: \smash{...}

How to superimpose the fake háček to a character:

  1. I build a box consisting of an alignment where the accent sits exactly on top of the character, centered on it. The \leavevmode is needed in case a paragraph starts with this accented character.

  2. Inside the box I set no baseline skip and no line skip, so the two boxes consisting of the accent and the character will sit on one another without any vertical separation.

  3. The alignment is obtained with a low level analogue to tabular with a c column.

The macro \makefakehacek checks whether the current font family is JosefinSans; in this case it does \fakehacek{#1} else it does #2. So, calling \fakehacek{Z}{Ž} the correct typesetting will be done.

Final step: tell XeLaTeX that we want Ž to be interpreted as \fakehacek{Z}{Ž} and this is a job for \newunicodechar.

The second example uses a different fake háček, built as above but with

\scalebox{1.2}[-.8]{\char"5E}}}

that expands the caron by 20% in the horizontal direction (1.2), compresses it by 20% in the vertical direction and flips it vertically because the scale is negative (-.8).

share|improve this answer
    
Very nice and very advanced... Could you explain in a little more detail how you obtained the caron? Also, do you by chance have any idea why my solution with editing the TTF file didn't work? –  texnic Oct 4 '12 at 14:31
    
@texnic I've added some explanations; why the editing of the TrueType fonts didn't work I can't say. –  egreg Oct 7 '12 at 22:42
add comment

Not really an answer, but I've found a work-around for those who might be in a similar desperate situation: I have basically repeated the approach, described in the question, using TeX itself:

\documentclass{article}
\usepackage{fontspec}
\usepackage{graphicx,trimclip}
\setsansfont{Josefin Sans}

\newcommand{\lz}{\marginbox*{0 1.8ex 0 0}{\rotatebox{180}{\clipbox{0 1.1ex 0 0}{ê}}}\hspace{-.45em}z}
\newcommand{\lZ}{\marginbox*{0 2.5ex 0 0}{\rotatebox{180}{\clipbox{0 2ex 0 0}{Ê}}}\hspace{-.63em}Z}

\begin{document}
\textsf{Kata\lz{}ina}
\end{document}

I will never stop being amazed by the power of TeX!

P.S. Now I am patiently waiting for the answer to the OP, since the above solution is really just a "solution". Besides, I am curious to find out what is wrong with my font editing approach.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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