Quantcast
Channel: Bugs in conditional structure in a newcommand definition with optional arguments - TeX - LaTeX Stack Exchange
Viewing all articles
Browse latest Browse all 2

Answer by egreg for Bugs in conditional structure in a newcommand definition with optional arguments

$
0
0

The test \IfNoValueTF is never true when the argument you refer to is declared as O, but only with o.

I suggest a change in syntax, because two optional arguments in a row are difficult to manage. Moreover, your argument #1 is assumed to be not empty, given the code.

\documentclass[11pt,a4paper]{article}\usepackage[T1]{fontenc}\usepackage[utf8]{inputenc}\usepackage[italian]{babel}\usepackage{amsmath}\usepackage{caption,float}\usepackage{xparse}\DeclareCaptionType{mycapequ}[][List of equations]\captionsetup[mycapequ]{labelformat=empty,textfont={bf,it}} \numberwithin{equation}{section}\NewDocumentCommand{\myeq}{ o m o }{%    \IfNoValueTF{#3}{%        %IF CAPTION {#3} IS EMPTY        \begin{equation}        \IfValueT{#1}{\label{eq:#1}}        #2        \end{equation}    }{%        %IF CAPTION {#3} IS NOT EMPTY        \begin{mycapequ}[H]        \setlength{\abovecaptionskip}{0pt}%        \begin{equation}        \IfValueT{#1}{\label{eq:#1}}        #2        \end{equation}        \caption{{#3}}        \end{mycapequ}    }}\begin{document}\myeq{U\left(S,V,N\right)=TS-pV+\mu N}[Forma finita di Eulero]text\myeq[y]{\sideset{_{(ir)rev}}{}\oint \frac{\delta Q}{T}\le 0}text and reference~\ref{eq:y}\end{document}

enter image description here

However, I'd prefer something like

\documentclass[11pt,a4paper]{article}\usepackage[T1]{fontenc}\usepackage[utf8]{inputenc}\usepackage[italian]{babel}\usepackage{amsmath}\usepackage{xparse}\numberwithin{equation}{section}\NewDocumentCommand{\myeq}{ o m o }{%    \IfNoValueTF{#3}{%        %IF CAPTION {#3} IS EMPTY        \begin{equation}        \IfValueT{#1}{\label{eq:#1}}        #2        \end{equation}    }{%        %IF CAPTION {#3} IS NOT EMPTY        \begin{gather}        \IfValueT{#1}{\label{eq:#1}}        #2\\        \textbf{\itshape #3}\notag        \end{gather}    }}\begin{document}text\myeq{U\left(S,V,N\right)=TS-pV+\mu N}[Forma finita di Eulero]text\myeq[y]{\sideset{_{(ir)rev}}{}\oint \frac{\delta Q}{T}\le 0}text and reference~\ref{eq:y}\end{document}

so you have no float problem.


Viewing all articles
Browse latest Browse all 2

Trending Articles