\newtcbinputlisting を使用して逐語的ボックスを作成するにはどうすればよいですか?

\newtcbinputlisting を使用して逐語的ボックスを作成するにはどうすればよいですか?

のようなコマンドを定義したいと思います\maplebox。たとえば、コマンド\maplebox{\latex}

次のコードはなぜコンパイルされないのでしょうか?

\documentclass{article}

\usepackage[svgnames]{xcolor}
\usepackage{tcolorbox}
\usepackage{amsmath,amsfonts,amssymb,amsthm}
\usepackage{lipsum}
 \usepackage[top=2.5cm,right=3.5cm,bottom=2.5cm,left=2.5cm]{geometry}      

\tcbuselibrary{listings,skins,theorems}

\newtcbinputlisting{\maplebox}[1][white]{
                                                            listing only,
                                                            nobeforeafter,
                                                            tcbox raise base,
%                                                           fontupper=\latinfont\setLTR\ttfamily\bfseries,
                                                            fontupper=\ttfamily\bfseries,
                                                            arc=0pt,
                                                            outer arc=0pt,
                                                            colback=#1!10!white,
                                                            colframe=#1!50!black,
                                                            boxsep=0pt,
                                                            left=1pt,
                                                            right=1pt,
                                                            top=2pt,
                                                            bottom=2pt,
                                                            boxrule=0pt,
                                                            bottomrule=1pt,
                                                            toprule=1pt}


\begin{document}

The \maplebox{\latex}

\end{document}

答え1

いくつかの問題/注意点があります。まず、\newtcbinputlistingは新しいリスト入力コマンドを作成しますが、私の考えが正しければ、ファイルを読み取りたくはありません。したがって、\newtcblistingを使用する必要があります。これにより、マクロではなく、逐語的な環境が作成されます。オプションのパラメータのみを含むこのような環境を使用することはお勧めしません。必須のパラメータがある場合は、オプションのパラメータも使用できます。

さて、私はあなたの例を少し変形しましたが、それがあなたにとって役立つことを願っています:

\documentclass{article}

\usepackage[svgnames]{xcolor}
\usepackage{tcolorbox}
\usepackage{amsmath,amsfonts,amssymb,amsthm}
\usepackage{lipsum}
\usepackage[top=2.5cm,right=3.5cm,bottom=2.5cm,left=2.5cm]{geometry}

\tcbuselibrary{listings,skins,theorems}

\newtcblisting{maplebox}[1]{
  listing only,
  colupper=black,
  nobeforeafter,
  hbox,
  tcbox raise base,
  fontupper=\ttfamily\bfseries,
  arc=0pt,
  outer arc=0pt,
  colback=#1!10!white,
  colframe=#1!50!black,
  boxsep=0pt,
  left=1pt,
  right=1pt,
  top=2pt,
  bottom=2pt,
  boxrule=0pt,
  bottomrule=1pt,
  toprule=1pt,
  }

\begin{document}

The
\begin{maplebox}{white}
\latex
\end{maplebox}
\
\begin{maplebox}{red}
\latex
\end{maplebox}
\
\begin{maplebox}{blue}
\latex
\end{maplebox}
\
\begin{maplebox}{green}
\latex
\end{maplebox}
\ test.

\end{document}

ここに画像の説明を入力してください

アップデート: パッケージの助けを借りればxparse、マクロ ソリューションが可能になります。 from パッケージに埋め込まれた\lstinlinefrom パッケージを使用します。書式設定オプションは に直接設定されます。listings\tcboxtcolorbox\lstinline

\documentclass{article}

\usepackage{xparse}
\usepackage[svgnames]{xcolor}
\usepackage{tcolorbox}
\usepackage{amsmath,amsfonts,amssymb,amsthm}
\usepackage{lipsum}
\usepackage[top=2.5cm,right=3.5cm,bottom=2.5cm,left=2.5cm]{geometry}

\tcbuselibrary{listings,skins,theorems}

\NewDocumentCommand{\maplebox}{ O{white} v}{%
  \tcbox[colupper=black,nobeforeafter,tcbox raise base,
    arc=0pt,outer arc=0pt,colback=#1!10!white,
    colframe=#1!50!black,
    boxsep=0pt,left=1pt,right=1pt,top=2pt,bottom=2pt,
    boxrule=0pt,bottomrule=1pt,toprule=1pt]{%
  \lstinline[style=tcblatex,texcsstyle=*\color{blue}\bfseries]§#2§}}

\begin{document}

\maplebox{\LaTeX}
\maplebox[red]{Some \LaTeX\ code}
\maplebox[blue]{$a^2+b^2=c^2$}
\maplebox[green]{\textbf{something}}

\end{document}

ここに画像の説明を入力してください

最終更新:同じ出力は、tcolorboxfrom version を使用したよりエレガントな構文で生成​​できます2.80 (2014/03/31)

\documentclass{article}

\usepackage[svgnames]{xcolor}
\usepackage{tcolorbox}
\usepackage{amsmath,amsfonts,amssymb,amsthm}
\usepackage{lipsum}
\usepackage[top=2.5cm,right=3.5cm,bottom=2.5cm,left=2.5cm]{geometry}

\tcbuselibrary{listings,skins,theorems,xparse}

\NewTotalTCBox{\maplebox}{ O{white} v}
{ colupper=black,nobeforeafter,tcbox raise base,
  arc=0pt,outer arc=0pt,colback=#1!10!white,
  colframe=#1!50!black,
  boxsep=0pt,left=1pt,right=1pt,top=2pt,bottom=2pt,
  boxrule=0pt,bottomrule=1pt,toprule=1pt}
{\lstinline[style=tcblatex,texcsstyle=*\color{blue}\bfseries]§#2§}

\begin{document}

\maplebox{\LaTeX}
\maplebox[red]{Some \LaTeX\ code}
\maplebox[blue]{$a^2+b^2=c^2$}
\maplebox[green]{\textbf{something}}

\end{document}

関連情報