编辑

编辑

我编译了这个代码

\documentclass{article}

\usepackage{minted, fontspec}

\setmonofont{UM Typewriter} %% <--- some problems here (see the next comment). To solve comment it out.

\begin{document}

%% $ sign overlaps a
\begin{minted}{R}
# print(acf(wind_speed, lag.max = lag, plot = FALSE)$acf) 
\end{minted}
    
\begin{minted}{R}
print(acf(wind_speed, lag.max = lag, plot = FALSE)$acf)
\end{minted}
    
\begin{minted}{R}
# print(acf(wind_speed, lag.max = lag, plot = FALSE)$ acf)
\end{minted}

\end{document}

惠特

latexmk -interaction=nonstopmode -shell-escape -synctex=1 -lualatex foo.tex

这就是结果错误的结果 因此,为了解决问题,我在$和之间添加了一个空格acf。但我认为这是一种不太好的解决方案,还有其他可靠的解决方案吗?还有其他会出现此错误的情况吗?

提前谢谢你,洛伦佐。

编辑

如果我更改如下所示的代码,Marcel 的答案将不起作用。

\documentclass{toptesi} %% <--- I changed THIS
\usepackage{fontspec}

% First define the feature. We set the width to the width of the space since the font is monospace
\directlua{
  fonts.constructors.features.otf.register{
    name = 'fix_umt_width',
    description = 'Overwrite width value of dollar in UM Typewriter',
    manipulators = {
      node = function(tfmdata)
        tfmdata.characters[\number`\$].width=tfmdata.parameters.space
      end,
    },
  }
}

% Then use it in the fontspec call
\setmonofont[RawFeature=+fix_umt_width]{UM Typewriter}

\begin{document}

\textit{\texttt{\string$acf}}

\end{document}

答案1

正如 David 所写,你可以在 LuaLaTeX 中通过添加更改字形宽度的功能来动态修复此问题:

\documentclass{article}
\usepackage{fontspec}

% First define the feature. We set the width to the width of the space since the font is monospace
\directlua{
  fonts.constructors.features.otf.register{
    name = 'fix_umt_width',
    description = 'Overwrite width value of dollar in UM Typewriter',
    manipulators = {
      node = function(tfmdata)
        tfmdata.characters[\number`\$].width=tfmdata.parameters.space
      end,
    },
  }
}

% Then use it in the fontspec call
\setmonofont[RawFeature=+fix_umt_width]{UM Typewriter}

\begin{document}

\textit{\texttt{\string$acf}}

\end{document}

在此处输入图片描述

答案2

它不是铸造的,斜体版本的字体产生:

在此处输入图片描述

\documentclass{article}

\usepackage{fontspec}

\setmonofont{UM Typewriter} %% <--- some problems here (see the next comment). To solve comment it out.


 
\begin{document}

\textit{\texttt{\string$acf\showthe\font}}

\end{document}

添加\showthe\fontcharwd\font`\$产品

> 0.0pt.

所以$宽度为零。

相关内容