Latex verbatim: show characters using a fallback font?

你。 提交于 2019-12-24 16:42:47

问题


I use a specific monofont for verbatim blocks. In one of my verbatim block, some characters are not included in the font. As suggested in this post, one can use either a different font, or use pmboxdraw package to render the un-supported characters. But it seems that it does not work for me.

The following is a MWE, in which the black circle (i.e., 1st character of the second line) can not be drawn correctly. My intention is that to use the monofont I used for the verbatim block, and use whatever substitute font for the black circle character. Is there a solution for that? Thanks a lot!

\documentclass{article}
\usepackage{fancyvrb}

\usepackage[utf8]{inputenc}
\usepackage{pmboxdraw}

\usepackage{fontspec}
\setmonofont[Path=./fonts/PragmataPro/,
    UprightFont=*-R,
    ItalicFont=*-RI,
    BoldFont=*-B,
    BoldItalicFont=*-BI]{PragmataPro}

\begin{document}
\begin{Verbatim}
$ systemctl status redsocks
● redsocks.service - Redsocks transparent SOCKS proxy redirector
   Loaded: loaded (/lib/systemd/system/redsocks.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2019-10-28 16:14:16 CST; 5s ago
  Process: 1499 ExecStart=/usr/sbin/redsocks -c ${CONFFILE} (code=exited, status=0/SUCCESS)
  Process: 1496 ExecStartPre=/usr/sbin/redsocks -t -c ${CONFFILE} (code=exited, status=0/SUCCESS)
\end{Verbatim}
\end{document}

The output using xelatex shows that the black circle is rendered incorrectly:

Btw, if I don't specify the customized monofont, the black circle will not be drawn at all.


回答1:


You can replace individual symbols with the newunicodechar package. You just need to find a font that contains the character, see e.g. https://www.fileformat.info/info/unicode/char/25cf/fontsupport.htm

% !TeX TS-program = xelatex

\documentclass{article}
\usepackage{fancyvrb}

\usepackage[utf8]{inputenc}
\usepackage{newunicodechar}

\usepackage{fontspec}
\setmonofont{Monaco}

\newfontfamily{\dejamono}{DejaVu Sans Mono}

\newunicodechar{●}{{\dejamono ●}}

\begin{document}
\begin{Verbatim}
$ systemctl status redsocks
● redsocks.service - Redsocks transparent SOCKS proxy redirector
   Loaded: loaded (/lib/systemd/system/redsocks.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2019-10-28 16:14:16 CST; 5s ago
  Process: 1499 ExecStart=/usr/sbin/redsocks -c ${CONFFILE} (code=exited, status=0/SUCCESS)
  Process: 1496 ExecStartPre=/usr/sbin/redsocks -t -c ${CONFFILE} (code=exited, status=0/SUCCESS)
\end{Verbatim}
\end{document}

(I'm using Monaco font for the example above, because this font also lacks the symbol and I don't have the proprietary PragmataPro font)



来源:https://stackoverflow.com/questions/58816096/latex-verbatim-show-characters-using-a-fallback-font

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!