I am typesetting documents with example code and I often typeset metasyntactical variables or text. For example :

In OCaml, one cannot assign values to variables like in Python
but one can bind the value of an expression \metasyn{expr} to
a variable \metasyn{v} and evaluate an expression with respect to it~:
   let $\metasyn{v}$ = $\metasyn{expr}$ in
       $\metasyn{code to evaluate}$

I want to display the metasyntactic elements with the normal math font, but in text mode, as it may contain spaces and generally should not use the interletter spacing rules of math mode.

I have been using (for two days !) fontspec and unicode-math with XeLaTeX. I use Asana-Math as my math font and my current definition of \metasyn is


But this sets the text to upright Asana-Math, not the math-italic glyphs. In other terms, how can I make $\metasyn{v}$ use the same glyph as $v$ while allowing for multiletter identifiers and multiple words to be typeset as I intend ?

I was previously using textit as with kpfonts, text mode italics and math glyphs look alike, but this is not the case anymore with Asana-Math and Gentium which I now intend to use.

mathit on the other hand does not respect spaces and is not affected by \setmathfont{Asana-Math.otf} and looks like the default (Computer modern ?) math italics.

  • Welcome to TeX.SX! Please help us (and also you) and add a minimal working example (MWE), that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass and ending with \end{document}. – Bobyandbob Jul 29 '17 at 13:50

You can't use the math-italic glyphs as text glyphs (at least not in a sensible, easy way). The glyphs are from the mathematical unicode block.

But Asana-Math is built from Palatino, so you can use as text font TeX Gyre Pagella:

\setmainfont{TeX Gyre Pagella}
\setmathfont{Asana Math}

\textit{abcde} $abcde$

enter image description here

If you want to use pagella only as \mathit font in combination with some other text font you can do it like this:


\setmathfont{Asana Math}

\textit{abcde} $abcdef \mathit{abcdef}$
  • This works, except that \mathit does respect spaces. I do not know if this is a bug or configurable ; it seems to be discussed there. But doing \text{\fontspec{texgyrepagella-italic.otf} #1} works. – ysalmon Jul 29 '17 at 13:54
  • What do you mean by "does respect spaces"? Do you mean "doesn't" instead? In math spaces are never respected. Imho you should at first decide if your variables are math or text, and then setup either a math alphabet like mathit, or a text font for it. Btw: The old discussion is no longer relevant, unicode-math has changed here. – Ulrike Fischer Jul 29 '17 at 13:59
  • Yes : does not respect spaces. You are right, switching to text mode to display some text makes more sense. In fact, they are a block that is typeset as text but behaves like a math element, so \text{} seems to be the thing to use. – ysalmon Jul 29 '17 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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