强制 tcolorbox 包中的 minted 不对单引号和重音符号进行样式化

强制 tcolorbox 包中的 minted 不对单引号和重音符号进行样式化

我有以下代码及其输出:

\documentclass[
    12pt,     
    openright,
    twoside,  
    a4paper,  
    english,  
    brazil,   
    draft
]{memoir}

\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[portuges]{babel}
\usepackage{color}
\usepackage[final]{graphicx}
\usepackage{microtype}
\usepackage[cache=false]{minted}
\usepackage[final]{pdfpages}
\usepackage{geometry}
\usepackage{tcolorbox}
\usepackage{tikz}
\usepackage{tkz-euclide}
\tcbuselibrary{minted,skins,breakable,xparse}
\usetikzlibrary{positioning}

\definecolor{corAzulTema}{RGB}{0,66,137}
\definecolor{corFundoCaixas}{RGB}{245,245,245}

\tcbset{
    listing engine=minted,
    minted options={fontsize=\small,linenos,numbersep=3mm,breaklines},
    colback=corFundoCaixas,
    colframe=corAzulTema!40,
    fonttitle=\bfseries,
    listing only,
    left=7mm,
    enhanced,
    breakable,
    drop fuzzy shadow,
    before skip=\baselineskip,
    grow to left by=13mm,grow to right by=15mm,
    overlay={\begin{tcbclipinterior}\fill[corAzulTema!40](frame.south west)rectangle([xshift=7mm]frame.north west);\end{tcbclipinterior}}
}

\newtcbinputlisting{\javaScriptCode}[3][]{%
    listing file={#3},
    title=\texttt{#2},
    colframe=corAzulTema,
    minted language=javascript
}

\DeclareTotalTCBox{\inlineJavaScriptCode}{ s v }{
    reset,
    listing only,
    on line,
    enhanced,
    nobeforeafter,
    tcbox raise base,
    boxrule=0.7pt,
    top=1mm,
    bottom=0mm,
    right=1mm,
    left=1mm,
    boxsep=0.5pt,
    before upper={\vphantom{dlg}},
    colback=corFundoCaixas,
    colframe=corAzulTema,
    drop fuzzy shadow,
    arc=3pt}
{\mintinline{javascript}{#2}}%

\begin{document}

\begin{enumerate}
    \item apostrophe/single quotes: \inlineJavaScriptCode{'string'}
    \item double quotes:  \inlineJavaScriptCode{"string"}
    \item grave: \inlineJavaScriptCode{`string`}
\end{enumerate}

\javaScriptCode{title}{strings.js}

\end{document}

在此处输入图片描述

JavaScript 文件(strings.js):

let s1 = 'string';    // apostrophe/single quotes
let s2 = "string";    // double quotes
let s3 = `string`;    // grave

我的问题是,当我使用命令时\inlineJavaScriptCode,单引号和重音符号被风格化了,但我希望它们像在使用读取外部文件时显示的那样呈现\javaScriptCode。有办法吗?

答案1

draft在类别选项中注释掉。

以非草稿模式铸造

所发生的情况是,minted看到draft选项并在不使用外部文件和花哨功能的情况下进行打印:draftfancyvrb单独用于所有排版;Pygments未使用。这会以语法突出显示和一些其他minted功能换取更快的编译。”(minted手册,第 12 页)

在 pdflatex 下,这种更快的方法看起来包括不阻止引号的标准连字或撤消它们(这是有道理的,因为连字信息存储在字体文件中.tfm)。

Lualatex 必须有不同的字体机制(并且也可以使用系统和 TTF/OTF 字体),但无论如何,lualatex 的草稿模式也没有语法高亮。

平均能量损失

\documentclass[
    12pt,     
    openright,
    twoside,  
    a4paper,  
    english,  
    brazil,   
%    draft
]{memoir}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[portuges]{babel}
\usepackage[final]{graphicx}
\usepackage{microtype}
\usepackage{minted}
\usepackage[final]{pdfpages}
\usepackage{geometry}
\usepackage{tcolorbox}

\usepackage{tikz}
\usepackage{tkz-euclide}
\tcbuselibrary{minted,skins,breakable,xparse}
\usetikzlibrary{positioning}

\definecolor{corAzulTema}{RGB}{0,66,137}
\definecolor{corFundoCaixas}{RGB}{245,245,245}

\tcbset{
    listing engine=minted,
    minted options={fontsize=\small,linenos,numbersep=3mm,breaklines},
    colback=corFundoCaixas,
    colframe=corAzulTema!40,
    fonttitle=\bfseries,
    listing only,
    left=7mm,
    enhanced,
    breakable,
    drop fuzzy shadow,
    before skip=\baselineskip,
    grow to left by=13mm,grow to right by=15mm,
    overlay={\begin{tcbclipinterior}\fill[corAzulTema!40](frame.south west)rectangle([xshift=7mm]frame.north west);\end{tcbclipinterior}}
}

\newtcbinputlisting{\javaScriptCode}[3][]{%
    listing file={#3},
    title=\texttt{#2},
    colframe=corAzulTema,
    minted language=javascript
}


\DeclareTotalTCBox{\inlineJavaScriptCode}{ s v }{
    reset,
    listing only,
    on line,
    enhanced,
    nobeforeafter,
    tcbox raise base,
    boxrule=0.7pt,
    top=1mm,
    bottom=0mm,
    right=1mm,
    left=1mm,
    boxsep=0.5pt,
    before upper={\vphantom{dlg}},
    colback=corFundoCaixas,
    colframe=corAzulTema,
    drop fuzzy shadow,
    arc=3pt}
{\mintinline{javascript}{#2}}%



\begin{document}

\begin{enumerate}
    \item apostrophe/single quotes: \inlineJavaScriptCode{'string' `` " ` ' `` ''}
    \item double quotes:  \inlineJavaScriptCode{"string"}
    \item grave: \inlineJavaScriptCode{`string`}
    \item line \inlineJavaScriptCode{let s1 = 'string';    // apostrophe/single quotes}
\end{enumerate}

\javaScriptCode{title}{strings.js}

\mintinline{javascript}{`string`}

\end{document}

相关内容