tcolorbox 作为一种风格

tcolorbox 作为一种风格

我正在使用 来tcolorbox标记一些关键字。我想控制何时标记这些关键字。所以我创建了一个布尔变量\l_style_bool。指令\bool_set_true:N \l_style_bool应该给出

在此处输入图片描述

并且指令\bool_set_false:N \l_style_bool应该给出

在此处输入图片描述

这是我的 MWE

\documentclass[a4paper,10pt]{article}

\usepackage{fullpage}
\usepackage{expl3}
\usepackage[all]{tcolorbox}

\ExplSyntaxOn
 % Used to apply or not the keyword style
 \bool_new:N \l_style_bool

 % Uncomment this to mark all keywords (1st picture)
 % \bool_set_true:N \l_style_bool

 % Uncomment this to hide the markup around the keywords (2nd picture)
 % \bool_set_true:N \l_style_bool
\ExplSyntaxOff
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~keyword~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\DeclareTotalTCBox{\keyword}{ O{green} m O{} }
 { fontupper=\ttfamily,nobeforeafter,tcbox raise base,arc=0pt,outer arc=0pt,
 top=0pt,bottom=0pt,left=0mm,right=0mm,
 leftrule=0pt,rightrule=0pt,toprule=0.3mm,bottomrule=0.3mm,boxsep=0.5mm,
 colback=#1!10!white,colframe=#1!50!black,colupper=red!75!black,#3}{#2}

\begin{document}
 Some text containing a \keyword{keyword}.
\end{document}

答案1

我不认为expl3这里需要使用语法。这看起来太过分了。但是,如果你必须这样做:

\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{xparse}
\ExplSyntaxOn
% Used to apply or not the keyword style
\bool_new:N \l_style_bool
% Uncomment this to mark all keywords (1st picture)
\bool_set_true:N \l_style_bool
% Uncomment this to hide the markup around the keywords (2nd picture)
\bool_set_false:N \l_style_bool
\NewDocumentCommand \keyword { O{green} m O{} }
{
  \bool_if:NTF \l_style_bool
  {
    \keywordbox [ #1 ] { #2 } { #3 }
  }
  {
    #2
  }
}
\ExplSyntaxOff
\DeclareTotalTCBox{\keywordbox}{ O{green} m O{} }
{%
  fontupper=\ttfamily,
  nobeforeafter,
  tcbox raise base,
  arc=0pt,
  outer arc=0pt,
  top=0pt,
  bottom=0pt,
  left=0mm,
  right=0mm,
  leftrule=0pt,
  rightrule=0pt,
  toprule=0.3mm,
  bottomrule=0.3mm,
  boxsep=0.5mm,
  colback=#1!10!white,
  colframe=#1!50!black,
  colupper=red!75!black,
  #3}{#2}

\begin{document}
 Some text containing a \keyword{keyword}.
\end{document}

会给

幻想是真的

在一个案例中

纯属错误

在另一个。

相关内容