I am trying to create a new command for add a caption and/or the label to an equation. The not optional parameter is for the text of the equation and first optional parameter is for the label, the second one for the caption. I wrote this code
\documentclass[11pt,a4paper]{article}\usepackage[italian]{babel}\usepackage[left=2.50cm, right=2.50cm, top=2.50cm, bottom=2.50cm]{geometry}\usepackage[utf8]{inputenc}\usepackage{amsmath}\usepackage{float}\usepackage{caption}\usepackage{xparse}\DeclareCaptionType{mycapequ}[][List of equations]\captionsetup[mycapequ]{labelformat=empty,textfont={bf,it}} \renewcommand{\theequation}{\thesection.\arabic{equation}}%\DeclareDocumentCommand{\myeq}{ O{} O{} m }{ %\newcommand{\myeq}[3][]{ \IfNoValueTF{#2}{ %IF CAPTION {#2} IS EMPTY \begin{equation} \label{eq:#1} {(!!) #3} \end{equation} %\vspace{-1em} }{ %IF CAPTION {#2} IS NOT EMPTY \begingroup \setlength{\abovecaptionskip}{0pt} \begin{mycapequ}[H] \begin{equation} \label{eq:#1} {(!) #3} \end{equation} \caption{{#2}} \end{mycapequ} \endgroup }}\begin{document} \myeq[][Forma finita di Eulero]{U\left(S,V,N\right)=TS-pV+\mu N} text \myeq[][]{\sideset{_{(ir)rev}}{}\oint \frac{\delta Q}{T}\le 0} text\end{document}
but the command does not work properly, infact I expect that was shown {(!!) #3} and not {(!) #3} in the second case:The possible usages I have thought are these:
1. \myeq{\vec{F}=m*\vec{a}} 2. \myeq[labe1][]{\vec{F}=m*\vec{a}} 2. \myeq[][2nd Newton's Law]{\vec{F}=m*\vec{a}} 3. \myeq[labe1][2nd Newton's Law]{\vec{F}=m*\vec{a}}