如何使 tcolorbox 与 XeLaTex 适配

如何使 tcolorbox 与 XeLaTex 适配

几个月前我已经切换到 XeLaTex,今天尝试包含具有以下参数的 Cisco IOS 代码(如何从路由器或交换机插入代码),就像我在使用 XeLaTex 之前所做的那样:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{booktabs}
\usepackage{etoolbox}
\usepackage[most]{tcolorbox}

\newtcblisting{cisco}[1][]{size=fbox, listing only, listing options={style=tcblatex,basicstyle=\ttfamily\scriptsize,tabsize=2,language=sh},#1}

\begin{document}

\begin{cisco}[title=Example of cisco command]
master#show ip cef 10.200.254.4
10.200.254.4/32, version 44, epoch 0, cached adjacency 10.200.200.2
0 packets, 0 bytes
    tag information set, all rewrites owned
    local tag: 20
    fast tag rewrite with Eth0/0/0, 10.200.200.2, tag imposed {18} via 10.200.200.2, Ethernet0/0/0, 0 dependencies
    next hop 10.200.200.2, Ethernet0/0/0
    valid cached adjacency
    tag rewrite with Et0/0/0, 10.200.200.2, tags imposed {18}
\end{cisco}

\end{document}

这会产生相同的输出,这正是我想要的。但是,我遇到了这个错误:

包 inputenc 错误:inputenc 不是为 xetex 或 luatex 设计的 \end{cisco}

我该怎么做才能继续使用 XeLaTex 并在我的文档中包含 Cisco IOS 代码而不会出现任何警告/错误?

先感谢您。

答案1

自动加载style=tcblatexinputenc

xelatex与或 一起使用时删除此键lualatex

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{booktabs}
\usepackage{etoolbox}
\usepackage[most]{tcolorbox}

\newtcblisting{cisco}[1][]{size=fbox, listing only, listing options={basicstyle=\ttfamily\scriptsize,tabsize=2,language=sh},#1}

\begin{document}

\begin{cisco}[title=Example of cisco command]
master#show ip cef 10.200.254.4
10.200.254.4/32, version 44, epoch 0, cached adjacency 10.200.200.2
0 packets, 0 bytes
    tag information set, all rewrites owned
    local tag: 20
    fast tag rewrite with Eth0/0/0, 10.200.200.2, tag imposed {18} via 10.200.200.2, Ethernet0/0/0, 0 dependencies
    next hop 10.200.200.2, Ethernet0/0/0
    valid cached adjacency
    tag rewrite with Et0/0/0, 10.200.200.2, tags imposed {18}
\end{cisco}

\end{document}

答案2

您必须inputencoding=utf8在 中options传递newtcblisting。这会将选项inputenc内部传递给包,这对于 Xe/Lua LaTeX 引擎来说是多余的(您会收到一条警告,说明它不是必需的,就是这样):

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{booktabs}
\usepackage{etoolbox}
\usepackage[most]{tcolorbox}

\newtcblisting{cisco}[1][]{size=fbox, listing only, listing options={style=tcblatex,basicstyle=\ttfamily\scriptsize,tabsize=2,language=sh,inputencoding=utf8},#1}

\begin{document}

\begin{cisco}[title=Example of cisco command]
master#show ip cef 10.200.254.4
10.200.254.4/32, version 44, epoch 0, cached adjacency 10.200.200.2
0 packets, 0 bytes
    tag information set, all rewrites owned
    local tag: 20
    fast tag rewrite with Eth0/0/0, 10.200.200.2, tag imposed {18} via 10.200.200.2, Ethernet0/0/0, 0 dependencies
    next hop 10.200.200.2, Ethernet0/0/0
    valid cached adjacency
    tag rewrite with Et0/0/0, 10.200.200.2, tags imposed {18}
\end{cisco}

\end{document}

给予:

在此处输入图片描述

答案3

tcolorbox你可以欺骗已经inputenc加载的包:

\documentclass{article}
\makeatletter\@namedef{[email protected]}{}\makeatother
\usepackage{fontspec}
\usepackage{booktabs}
\usepackage{etoolbox}
\usepackage[most]{tcolorbox}

\newtcblisting{cisco}[1][]{size=fbox, listing only, listing 
options={style=tcblatex,basicstyle=\ttfamily\scriptsize,tabsize=2,language=sh},#1}

\begin{document}

\begin{cisco}[title=Example of cisco command]
  master#show ip cef 10.200.254.4
  10.200.254.4/32, version 44, epoch 0, cached adjacency 10.200.200.2
  0 packets, 0 bytes
  tag information set, all rewrites owned
  local tag: 20
  fast tag rewrite with Eth0/0/0, 10.200.200.2, tag imposed {18} via 10.200.200.2, 
  Ethernet0/0/0, 0 dependencies
  next hop 10.200.200.2, Ethernet0/0/0
  valid cached adjacency
  tag rewrite with Et0/0/0, 10.200.200.2, tags imposed {18}
\end{cisco}

\end{document}

在此处输入图片描述

相关内容