3

I need to insert accented letter é, è, à. within labels in a matapost code. how can I do that

Note: I compile my document with pdflatex --shell-escape

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{mpgraphics}

\begin{document}

\begin{mpdisplay}
 pair A;
    A := (0,0);
    draw A withpen pencircle scaled 4bp;
    label.lft(btex  café  etex, A);
    label.rt (btex algèbre  etex, A);
\end{mpdisplay}

\end{document}

enter image description here

  • Perhaps add \usepackage{lmodern} to your code? (or any font which exists in T1 encoding). – Bernard Aug 1 '16 at 8:43
  • It seems as if you'd have to insert them separately, e.g. é has to be inserted as \'{e}. – Henri Menke Aug 1 '16 at 9:17
  • I have a similar question tex.stackexchange.com/questions/366081/… – Arwed Mett Apr 22 '17 at 14:58
4

You have to tell Metapost that you're using UTF-8 and T1:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{mpgraphics}

\begin{ltxpreamble}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\end{ltxpreamble}

\begin{document}

\begin{mpdisplay}
 pair A;
    A := (0,0);
    draw A withpen pencircle scaled 4bp;
    label.lft(btex \strut café  etex, A);
    label.rt (btex \strut algèbre  etex, A);
\end{mpdisplay}

\end{document}

enter image description here

With gmp it would be

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[shellescape,latex]{gmp}

\usempxpackage[T1]{fontenc}
\usempxpackage[utf8]{inputenc}

\begin{document}

\begin{mpost}
 pair A;
    A := (0,0);
    draw A withpen pencircle scaled 4bp;
    label.lft(\btex \strut café  etex, A);
    label.rt (\btex \strut algèbre  etex, A);
\end{mpost}

\end{document}
4

I suggest using LuaTeX. There you have UTF-8 support out-of-the-box when you use a correctly mapped font (by loading fontspec). Also, LuaTeX has a builtin Metapost processor which removes the necessity for shell escape. You have to load luamplib for that. Perhaps there are also other, higher-level packages for this which I am not aware of.

\documentclass{article}
\usepackage{fontspec}
\usepackage{luamplib}
% for convenience
\everymplib{verbatimtex \leavevmode etex; beginfig(0);}
\everyendmplib{endfig;}

\begin{document}

\begin{mplibcode}
  pair A;
  A := (0,0);
  draw A withpen pencircle scaled 4bp;
  label.lft(btex  café  etex, A);
  label.rt (btex algèbre  etex, A);
\end{mplibcode}

\end{document}

enter image description here


Or just use ConTeXt (same output). Thanks to Metafun you don't even need the annoying btex .. etex, but can just use quotes.

\starttext
\startMPcode
  pair A;
  A := (0,0);
  draw A withpen pencircle scaled 4bp;
  label.lft("café", A);
  label.rt ("algèbre", A);
\stopMPcode
\stoptext
  • Thanks @HenriMenke, but I need to compile my file with pdflatex – Salim Bou Aug 1 '16 at 11:45
  • Note that you'll want the struts as egreg used to get the two words on the same baseline (at least in luatex). – dedded Nov 11 at 0:39

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.