# Text label in MetaPost: language support

I am working with the example:

beginfig(1);
label.urt("Текст на русском.", origin);
label.llft("Text in English.", origin);
endfig;


The output contains:

Missing character: There is no 208 in font cmr10!
Missing character: There is no 162 in font cmr10!
Missing character: There is no 208 in font cmr10!
...


What I've tried:

• different values of the prologues variable (1,2 and 3)
• in the beginning of the .mp file I wrote:
verbatimtex
\usepackage[utf8]{inputenc}
\usepackage[T2A]{fontenc}
\usepackage[russian]{babel}
\nofiles
etex;

• also I added to the mpost command an option -tex=latex (hoping MetaPost would take the language settings in LaTeX...)

As I understand, the cmr10 font contains Russian symbols. So what do I have to tell MetaPost that it would 'understand' these letters? I've looked through the MetaPost Manual and browsed over the Internet about the problem -- nothing found...

• This is pretty much a duplicate of this question.... Dec 4, 2021 at 14:51

## 2 Answers

It is possible to get this to work with good old mpost, but it is 2021 now and frankly it is much easier to use lualatex instead. If I wrap the OP example up in luamplib, and choose an appropriate font with good Unicode support, like this:

\documentclass[border=5mm]{standalone}
\usepackage{fontspec}
\setmainfont{Linux Libertine O}
\usepackage{luamplib}
\mplibtextextlabel{enable}
\begin{document}
\begin{mplibcode}
beginfig(1);
label.urt("Текст на русском.", origin);
label.llft("Text in English.", origin);
endfig;
\end{mplibcode}
\end{document}


then compiling with lualatex produces this:

which is probably what you want. Notice that the font selection is done at the LaTeX level and that Unicode UTF8 is the default encoding.

I do all of my MP work like this now, simply for the better integration with LaTeX. And if you can't use lualatex for the rest of your document, then you can at least produce separate PDF files using the standalone class, as my example shows.

For documentation, try texdoc luamplib on your local system. Or have a look at sections 11 and 12 of my Drawing with Metapost document (in preparation...). And this earlier answer.

## Plain old Metapost version

If you are (for whatever reason) really stuck with plain mpost, then you might be able to get away with something like this.

prologues := 3;
outputtemplate := "%j%c.eps";

def CY primary s = if string s: decode_some_cyrillic(s) infont "fcmr6z" fi enddef;

vardef decode_some_cyrillic(expr given) =
save a, b, i, s, out; string s, out; numeric a, b, i;
out = ""; i=0;
forever:
s := substring (i, incr i) of given;
a := ASCII s;
if a < 128:
elseif a = 208:
s := substring (i, incr i) of given;
b := ASCII s;
s := if (143 < b) and (b < 192): char (b + 48) else: "?" fi;
elseif a = 209:
s := substring (i, incr i) of given;
b := ASCII s;
s := if (127 < b) and (b < 144): char (b + 112) else: "?" fi;
else:
s := "?";
fi
out := out & s;
exitif i >= length given;
endfor
out
enddef;

beginfig(1);
label.top(CY"Текст на русском.", origin);
draw (left--right) scaled 2cm;
endfig;
end


Provided that your system has a Cyrillic font called fcmr6z then compiling this with plain mpost should produce:

And just for reference, here is the font layout:

But the luamplib solution is a much better way to go!

It is possible to get this to work like good old mpost: using minim-mp, which includes a format file that allows you to use luatex as if it were a stand-alone metapost-to-pdf processor.

Minim-mp is based on plain TeX, so you have to specify the font in your metapost file like this:

verbatimtex
\font \cmu = {CMU Serif Roman} at 10pt
etex;

beginfig(1);
defaultfont := "cmu";
label.urt("Текст на русском.", origin);
label.llft("Text in English.", origin);
endfig;

bye


You can then compile it with luatex -fmt minim-mp <filename>.mp. (If the format file is not found, you should create it first with luatex -ini minim-mp.ini.)

• Welcome to TeX.SE! Dec 13, 2021 at 16:13