Latex:重置字体样式

发布于 2024-08-17 17:26:49 字数 1625 浏览 3 评论 0原文

有没有办法重置特定字符序列的样式? 我使用 listings 包来显示源代码,并使用 prebreak 属性来显示转义字符 \ 来指示当前行已被破坏。问题是,有时由于使用了语法突出显示,反斜杠会被着色。

所以我基本上需要类似 resetstyle 语句的东西,如以下想象的示例所示:

\textbf{Some bold text \resetstyle{not bold, no color} foo bar}

编辑: 以下是我通过 lstset 使用的设置:

\lstset{
        extendedchars           = \true,
        inputencoding           = utf8,
        basicstyle              = \scriptsize\ttfamily,
        breaklines              = true,
        breakindent             = 10pt,
        breakatwhitespace       = true,
        breakautoindent         = true,                         
        prebreak                = \\,
        frame                   = leftline,
        showtabs                = true,                                                                                                    
        numbers                 = left,                                                                                                                                                
        stepnumber              = 2,
        numberstyle             = \footnotesize,
        numbersep               = 10pt,
        keywordstyle            = \color[RGB]{0,0,255},
        commentstyle            = \itshape\color[RGB]{120,120,120},
        stringstyle             = \color[rgb]{0.627,0.126,0.941},
        emphstyle               = {[0]\color[RGB]{236,0,168}},
        emphstyle               = {[1]\color[RGB]{34,139,34}\underbar},
        emphstyle               = {[2]\textbf}
}

Is there a way I can reset the style of a certain character sequence?
I'm using the listings package to display source code and the prebreak property to display a escape character \ to indicate that the current lines was broken. The problem is that sometimes the backslash is colored because of the syntax highlighting used.

So I need basically something like a resetstyle statement, as in the following imaginary example:

\textbf{Some bold text \resetstyle{not bold, no color} foo bar}

EDIT:
Here are the settings that I'm using via lstset:

\lstset{
        extendedchars           = \true,
        inputencoding           = utf8,
        basicstyle              = \scriptsize\ttfamily,
        breaklines              = true,
        breakindent             = 10pt,
        breakatwhitespace       = true,
        breakautoindent         = true,                         
        prebreak                = \\,
        frame                   = leftline,
        showtabs                = true,                                                                                                    
        numbers                 = left,                                                                                                                                                
        stepnumber              = 2,
        numberstyle             = \footnotesize,
        numbersep               = 10pt,
        keywordstyle            = \color[RGB]{0,0,255},
        commentstyle            = \itshape\color[RGB]{120,120,120},
        stringstyle             = \color[rgb]{0.627,0.126,0.941},
        emphstyle               = {[0]\color[RGB]{236,0,168}},
        emphstyle               = {[1]\color[RGB]{34,139,34}\underbar},
        emphstyle               = {[2]\textbf}
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不知在何时 2024-08-24 17:26:49
\def\resetstyle#1{{\normalsize\rm\color[rgb]{0,0,0}\noindent#1}}
\def\resetstyle#1{{\normalsize\rm\color[rgb]{0,0,0}\noindent#1}}
悲歌长辞 2024-08-24 17:26:49

您可以尝试将文本放入 mbox 中(未经测试,但适用于数学模式):

\textbf{Some bold text \mbox{not bold, no color} foo bar}

您将失去在文本内换行的能力,但在这种情况下,这似乎没有问题。

You could try putting the text inside an mbox (untested, but works for math mode):

\textbf{Some bold text \mbox{not bold, no color} foo bar}

You will lose the ability for line breaks inside the text, but in this case that seems to be no problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文