
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 newtcbox
no 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}
Li sobre \tcboxmath
e \tcbhighmath
no 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}
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 \mywboxmath
esteja no modo matemático.
Responder2
Você pode fazer isso usando \tcboxmath
a theorems
biblioteca 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}
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/opacityback
uma pele usando umquebra-cabeçamecanismo de quadro, como standard jigsaw
ou 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}