Tornando o fundo da caixa transparente

Tornando o fundo da caixa transparente

Como no meu documento tenho que escrever muita matemática em caixas coloridas, gostaria de evitar escrever $ dentro de cada caixa. Existe uma maneira de definir newtcboxno modo matemático?

Eu tentei com \newtcbox{\mywbox}[1]{<options>}{$\displaystyle #1$}mas não funciona.

Este é o meu código de látex:

\usepackage{tcolorbox}
\newtcbox{\mywbox}{on line,colback=white,colframe=black,size=fbox,arc=3pt,boxrule=0.8pt}

\begin{document}
\obeylines

This \mywbox{$3x$} is in line math.
This $$y=\mywbox{$-5x$}-5+6$$ is not in line math.

\end{document}

insira a descrição da imagem aqui

Li sobre \tcboxmathe \tcbhighmathno manual oficial do tcolorbox, mas não entendo como defini-los simplesmente como newtcbox e se são o que preciso.

Responder1

eu diria

\newtcbox{\mywboxtext}{on line,colback=white,colframe=black,size=fbox,arc=3pt,boxrule=0.8pt}
\newcommand{\mywboxmath}[1]{\mywboxtext{$#1$}}

Seu exemplo pode se tornar

\documentclass{article}
\usepackage{tcolorbox}

\newtcbox{\mywboxtext}{on line,colback=white,colframe=black,size=fbox,arc=3pt,boxrule=0.8pt}
\newcommand{\mywboxmath}[1]{\mywboxtext{$#1$}}

\begin{document}

This \mywboxmath{3x} is in line math and this
\[
y=\mywboxmath{-5x}-5+6
\]
is display math.

\end{document}

insira a descrição da imagem aqui

Mude os nomes ao seu gosto.

Evite $$em LaTeX(e claro também \obeylines).

Caso você precise que as caixas se comportem em subscritos ou sobrescritos, altere o código para

\documentclass{article}
\usepackage{tcolorbox}

\newtcbox{\mywboxtext}{on line,colback=white,colframe=black,size=fbox,arc=3pt,boxrule=0.8pt}

\makeatletter
\newcommand{\mywboxmath}[1]{\mathpalette\mywboxmath@do{#1}}
\newcommand{\mywboxmath@do}[2]{\mywboxtext{$\m@th#1#2$}}
\makeatother

\begin{document}

This $\mywboxmath{3x}$ is in line math and this
\[
y_{\mywboxmath{0}}=\mywboxmath{-5x}-5+6
\]
is display math.

\end{document}

Observe que neste caso você precisa que \mywboxmathesteja no modo matemático.

Responder2

Você pode fazer isso usando \tcboxmatha theoremsbiblioteca de tcolorbox:

\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{theorems}

\newcommand*{\mywbox}{%
  \tcboxmath[colback=white, colframe=black, size=fbox, arc=3pt, boxrule=0.8pt]%
}

\begin{document}

This \mywbox{3x} is in line math.
This
\[ y = \mywbox{-5x} - 5 + 6 \]
is not in line math.

\end{document}

Captura de tela

Você pode querer abstrair um pouco as coisas usando um estilo também, para que possa aplicá-lo a outras caixas caso seja necessário:

\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{theorems}

\tcbset{my math box/.style={
          colback=white, colframe=black, size=fbox, arc=3pt, boxrule=0.8pt}
}

\newcommand*{\mywbox}{\tcboxmath[my math box]}

\begin{document}

This \mywbox{3x} is in line math.
This
\[ y = \mywbox{-5x} - 5 + 6 \]
is not in line math.

\end{document}

Tornando o fundo da caixa transparente

Isso pode ser feito usando /tcb/opacitybackuma pele usando umquebra-cabeçamecanismo de quadro, como standard jigsawou enhanced jigsaw.

\documentclass[fleqn]{article}
\usepackage{tcolorbox}
\tcbuselibrary{theorems}

\tcbset{
  my math box/.style={
    standard jigsaw,   % useful for 'opacityback' and 'opacityframe'
    colback=green!20, colframe=black, size=fbox, arc=3pt, boxrule=0.8pt,
    opacityback=0.6,
  }
}

\newcommand*{\mywbox}{\tcboxmath[my math box]}

\begin{document}

This \makebox[0pt]{%
  \raisebox{-0.5\height}[0pt][0pt]{\hspace{1cm}\includegraphics{example-image-duck}}%
  }%
\mywbox{3x} is in line math.
This
\[ y = \mywbox{-5x} - 5 + 6 \]
is not in line math.

\end{document}

insira a descrição da imagem aqui

informação relacionada