我定义了一些小宏来标记函数名称:
\lstdefinestyle{inline-funcname}{
columns=fullflexible,
breaklines=false,
%Note: \usefont{OML}{cmm}{m}{it} is exactly like \mathnormal
basicstyle=\usefont{OML}{cmm}{m}{it} %\itshape\ttfamily
}
\newcommand{\ifuncname}[1]{\lstinline[style=inline-funcname]{#1}}
效果非常好。
唯一有时会有点混乱的情况是在行尾:
有没有办法可以改善这种情况或完全避免这种情况?
答案1
请记住,这ReductionMatrices_Calc
不是您使用的语言中已知的“单词”(...实际上,在任何地方)。因此,如果没有任何连字符模式的指示,TeX 将不会执行任何操作。最简单的解决方案是稍微改写段落,使其不放在ReductionMatrices_Calc
换行符周围。也许
The function \ifuncname{calcMatrix} in the class \ifuncname{ReductionMatrices_Calc}
implements the algorithm ...
最后,虽然这里没有什么区别,但您也可以使用以下实现\ifuncname
:
\newcommand{\ifuncname}{\lstinline[style=inline-funcname]}
请注意,我已删除 的参数捕获\ifuncname
,依靠替换文本来处理该问题。这在处理宏参数中的类别更改时有时很有用。但是,listings
很好地处理了这些引用。
遵循以下一些想法下划线使文本超出行尾进入边距您还可以发出\linebreak
:
\documentclass{article}
\usepackage[margin=1.5in]{geometry}% Just for this example
\usepackage{listings}
\lstdefinestyle{inline-funcname}{
columns=fullflexible,
breaklines=false,
%Note: \usefont{OML}{cmm}{m}{it} is exactly like \mathnormal
basicstyle=\usefont{OML}{cmm}{m}{it} %\itshape\ttfamily
}
\newcommand{\ifuncname}{\lstinline[style=inline-funcname]}
\begin{document}
\noindent
This algorithm has been implemented in the function \ifuncname{calcMatrix} in the class\linebreak \ifuncname{ReductionMatrices_Calc}
in the file \verb|algo_cpp.cpp|. All the state and parameters are stored in the class so that we
need to copy as little data as possible for successive $S \in \mathcal{P}_2(\mathcal{O})$. That is also why the iteration
through different $S \in \mathcal{P}_2(\mathcal{O})$ (see section~4.4) has been done in C++.
\end{document}