\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}

관련 정보