# Custom phonetic font with tipa and fontspec

I've been trying to typeset a document that has a lot of phonetic transcriptions, and I'm trying to do it using Tex Gyre Bonum for the body and Charis SIL for the phonetic transcriptions. I'm trying to load these with fontspec, but tipa is famous for not playing along when fontspec is involved.

My initial attempt (based on egreg's answer to this question) was to redefine the textipa command to use a custom font:

\newfontfamily{\ipafont}{Charis SIL}
\AtBeginDocument{
\renewcommand\textipa[1]{{\ipafont\tipaencoding #1}}
}


but that didn't work (see image below to see how it didn't work). What is odd is that it did work if I used the same instructions in an entirely new command and using the default textipa command. But that, of course, meant that the source was no longer compilable using regular tipa...

So, how can I redefine textipa to work with a font of my choosing without having to input some of the characters myself?

Here's an MWE to show all the different types of fail:

\documentclass{article}
\usepackage{tipa}
% \expandafter\def\csname ver@xunicode.sty\endcsname{}
\usepackage{fontspec}

\setmainfont{TeX Gyre Bonum}
\newfontfamily{\ipafont}{Charis SIL}

\newcommand{\mytipa}[1]{{\ipafont \textipa{#1}}}

\begin{document}

\begin{itemize}

\item This works only without \texttt{fontspec}:
\textipa{\t{\=*{t}S}}

\item With \texttt{fontspec} and custom \texttt{ipafont}
this fails:
{\ipafont \textipa{\t{\=*{t}S}}}
; but this works:
{\ipafont \textipa{\t{ṯS}}}

\item Likewise, with a custom command,
this fails:
\mytipa{\t{\=*{t}S}}
; but this works:
\mytipa{\t{ṯS}}

\renewcommand\textipa[1]{{\ipafont \tipaencoding #1}}

\item But with a redefined \texttt{textipa} command
this fails:
\textipa{\t{\=*{t}S}}
; and this \textit{also} fails:
\textipa{\t{ṯS}}

\end{itemize}

\end{document}


And the output:

ALSO: In a follow-up question Joseph Wright recently provided a solution to similar issues to those raised when compiling the MWE (and that's the commented line at the beginning). However, as you can see by uncommenting it, even though it makes all the lines work (except those with ṯ in the source), it makes them work using the default tipa font, which is not what I want.

An indirect answer to your question may be not to use TIPA at all. You can use the IPA keyboard provided by SIL instead to easily enter IPA characters.

You can find it at IPA Unicode Keyboards.

• Yes, I'm aware of this sort of methods. But - like I said in my question linked to above - "since all my transcriptions are already typed out using tipa, I'm reluctant to give it up and start doing the charmap spelunking that would be necessary". And even in cases that allow for less obscure methods, I prefer the tipa interface, that allow for more and more specific control of the phonetic features and their position. To me, the opposite is similar to typesetting equations without LaTeX.
– jja
Oct 13 '13 at 17:13
• I perfectly understand your point. In this case, you could consider using other input methods as a last resort. I never had problems using direct input methods, like from keyboard. And Charis SIL does its magic. Perfect diacritic stacking and rendering, so no need for other specific controls. But this is personal preference. Oct 15 '13 at 11:30

The old xunicode package converts tipa symbols to Unicode.

The combining diacritical marks, at least the inverted double breve (U+0361), will need a helping hand. (I haven't tested the entire CDM block.)

The xunicode package (designed when xelatex was the only UTF8-aware engine) can run under LuaLatex with one additional line (see MWE).

CMU Serif font is the Unicode version of the 'tipa font' and embeds tipa symbols (note: for some glyphs, the Private Use Area is used, for non-standard Unicode glyphs, like 'turned f', which is at U+F16C).

MWE

\documentclass{article}
\usepackage{xcolor}
\usepackage{fontspec}
\def\XeTeXpicfile{}%so can compile with LuaLatex
\usepackage{xunicode}

\newcommand\ipafontname{Charis SIL}
\newcommand\fnamea{TeX Gyre Bonum}
\newcommand\fnameb{Noto Serif}
\newcommand\fnamec{CMU Serif}

\setmainfont{\fnamea}
\newfontfamily{\ipafont}{\ipafontname}[Colour=red]
\newfontfamily{\ffontb}{\fnameb}[Colour=blue]
\newfontfamily{\ffontc}{\fnamec}[Colour=brown]
\newfontfamily{\fmain}{\fnamea}

\newcommand\cdmdoubleinvertedbreve{\symbol{865}}
\renewcommand{\t}{\cdmdoubleinvertedbreve}

\newcommand\ttext{\textipa{\*k\*f\*t\*r\*w -- {\=*{t}\t S}}}

\begin{document}

\begin{quotation}

The command

\verb|\textipa{\*k\*f\*t\*r\*w -- {\=*{t}\t S}}}}|

gives:

\begin{quotation}
\begin{tabular}{ll}
Font & Result \\
\ipafontname & \ipafont\ttext \\
\fnameb & \ffontb\ttext \\
\fnamec & \ffontc\ttext \\
\end{tabular}
\end{quotation}
\end{quotation}

\fmain In Unicode, some of the turned letters are:

\begin{quotation}
\ffontb
Ɯ ǝ Ʌ ɐ ɒ ɥ ɯ ɰ ɹ ɺ ɻ  ʇ ʌ ʍ ʎ ʞ ʮ ʯ oʴ oʵ ᴂ ᴈ ᴉ ᴔ ᴚ oᵄ oᵆ oᵌ oᵎ oᵚ ᵷ oᶛ oᶣ oᶭ oᶺ (\fnameb\ font)

\ffontc
Ɯ ǝ Ʌ ɐ ɒ ɥ ɯ ɰ ɹ ɺ ɻ  ʇ ʌ ʍ ʎ ʞ ʮ ʯ oʴ oʵ ᴂ ᴈ ᴉ ᴔ ᴚ oᵄ oᵆ oᵌ oᵎ oᵚ ᵷ oᶛ oᶣ oᶭ oᶺ (\fnamec\ font)
\end{quotation}

\end{document}


Try the new tipauni package:

\documentclass[12pt]{article}
\usepackage[%
documentfont=TeX Gyre Bonum% Note that this isn't usually
% recommended as you'll have to
% use the font command for IPA
% every time you type
% IPA. Using a uniform IPA font
% e.g. Doulos SIL/Gentium might
% be the best choice. Charis
% SIL is the default one loaded
% by tipauni.
]%
{tipauni}% This automatically loads package fontspec.
\newfontfamily\ipafont{CharisSIL}
\newcommand\mytipa[1]{\ipafont\textipa{#1}}

\begin{document}
\begin{itemize}
\item With \texttt{fontspec} and a custom \texttt{ipafont}
this works:

\verb|{\ipafont\textipa{\t{{\=*{t}}S}}}|:
{\ipafont\textipa{\t{{\=*{t}}S}}};

and this works too:

\verb|{\ipafont\textipa{\t{ṯS}}}|:
{\ipafont\textipa{\t{ṯS}}}

\item Likewise, with a custom command, this works:

\verb|\mytipa{\t{{\=*{t}}S}}|:
\mytipa{\t{{\=*{t}}S}};

and this one too:

\verb|\mytipa{\t{ṯS}}| \mytipa{\t{ṯS}}
\end{itemize}
\end{document}


Note that as pointed out here, by Skillmon your TIPA syntax for getting ṯ͡ʃ is incorrect. You shall use \textipa{\t{{\=*{t}}S}}} in order to get correct results.

• Very nice! I haven't used LaTeX in a while now, but I'm glad to see new solutions coming up in this space, and I like seeing the positive effects even five-year-old questions still have. Keep up the good work! :D
– jja
Oct 11 at 9:55