Problem
I am trying to put a bunch of optional arguments in a new tcolorbox definition, and trying to use the ifmtarg so I can skip some optional arguments like in the following syntax:
Example 1: A
tcolorboxwith 6 argumentsHere is a tcolorbox with 6 arguments and how it is meant to be specified when leaving out the 5th argument (which is meant to be optional):
\begin{mybox}*[before title text]{mandatory title}[width][][extra options]Here, the
*acts as#1,before title textas#2,mandatory titleas#3,widthas#4,-NoValue-(empty) as#5, andextra optionsas#6.In
xargsterms, it would be like:{ s O m O O O }.
I tried defining a new tcolorbox environment that does this (sort of following this answer), but I messed up and keep getting errors such as:
! LaTeX cmd Error: Bad argument specification ' s O{\textbf {Figure
(cmd) \thetcbcounter :}~} m O O O ' for environment
(cmd) 'figurebox'.
For immediate help type H <return>.
...
l.46 }
The argument specification provided is not valid: one or more mandatory parts
are missing.
LaTeX will ignore this entire definition.
MWE
\documentclass[12pt, a4paper]{article}
% Layout
\usepackage[margin=2cm]{geometry}
% Colour
\usepackage[dvipsnames, cmyk]{xcolor}
% Graphing and math
\usepackage{amsmath}
\usepackage{pgfplots}
\pgfplotsset{%
compat=1.18,
trig format plots=rad,
My Style 1/.style={%
axis lines=middle,
xlabel={$x$},
ylabel={$y$},
xtick=\empty,
ytick=\empty,
label style={font=\footnotesize},
major tick style={semithick}
},
}
% Arguments
\usepackage{ifmtarg}
% tcolorbox
\usepackage{tcolorbox}
\tcbuselibrary{%
skins
}
%% Custom tcolorboxes
\NewTColorBox
[auto counter, number within=part]
{figurebox}
{ s O{\textbf{Figure \thetcbcounter:}~} m O O O } % {1: left or not, 2: before title declaration, 3: title, 4: width, 5: colour, 6: extra options}
{
enhanced,
title=#3,
fonttitle=\scriptsize,
colframe=\IfNoValueTF{#5}{Violet}{\makeatletter@ifmtarg{#5}{Violet}{#5}\makeatother},
colback=\IfNoValueTF{#5}{Violet!5!white}{\makeatletter@ifmtarg{#5}{Violet}{#5!5!white}\makeatother},
before title=#2,
arc=3.5mm,
sharp corners=downhill,
width=\IfNoValueTF{#4}{6cm}{\makeatletter@ifmtarg{#4}{6cm}{#4}\makeatother},
boxsep=0pt,
left=4pt,
right=4pt,
top=4pt,
bottom=4pt,
leftrule=\IfBooleanTF{#1}{3mm}{0.5mm}, % initial is 0.5mm
rightrule=\IfBooleanTF{#1}{0.5mm}{3mm}, % initial is 0.5mm
\IfNoValueTF{#6}{}{\makeatletter@ifmtarg{#6}{}{#6}\makeatother}
}
\title{\TeX{}.SE MWE}
\author{BrightBulb123}
\begin{document}
\maketitle
\section{Introduction}
\begin{figurebox}{Graph of ( \sin(x) )}[\linewidth][][center upper, valign=center, halign=center, tikz upper]
\begin{axis}[My Style 1, xmin=-4pi, xmax=4pi, ymin=-1.25, ymax=1.25, width=\linewidth]
\addplot[black, thick, samples=400, domain=-4pi:4pi] {sin(x)};
\end{axis}
\end{figurebox}
\end{document}
\IfBlankTF{var}{true}{false}? – daleif Mar 15 '24 at 13:17\makeatletter...\makeatother, place it around the whole macro definition, not within the definition. – Steven B. Segletes Mar 15 '24 at 13:22