2

I want to define an environment that uses two optional arguments, but i want to be able to use one with <> and the other with []

Here is what I have done:

\NewDocumentCommand\why{O{\equiv}m}%
    { #1 & \quad\langle\;\text{{#2}}\;\rangle }

\NewDocumentCommand\res{m}% { & #1}

\NewDocumentCommand\To{}{\Rightarrow}

\NewDocumentEnvironment{derivation}{D<>{1.2} O{0pt}}{ \begingroup \renewcommand{\arraystretch}{#1} \setlength{\tabcolsep}{#2} \begin{tabular}{>{$}l<{$} >{$}l<{$}} }{ \end{tabular} \endgroup }

When I try to use any of the optional arguments either they print in the pdf or I just get an error. How can I fix this?

The code of the example is:

\documentclass{article}
\usepackage{xparse}
\usepackage{mathtools}
\usepackage{nicematrix}
\usepackage[spanish]{babel}

\ExplSyntaxOn \NewDocumentCommand\why{O{\equiv}m}% { #1 & \quad\langle;\text{{#2}};\rangle }

\NewDocumentCommand\res{m}% { & #1}

\NewDocumentCommand\To{}{\Rightarrow}

\NewDocumentEnvironment{derivation}{D<>{1.2} O{0pt}}{ \renewcommand{\arraystretch}{#1} \setlength{\tabcolsep}{#2} \begin{tabular}{>{$}l<{$} >{$}l<{$}} }{ \end{tabular} } \ExplSyntaxOff

\begin{document} \begin{center} \begin{derivation}<1.5> \res{ (p \To \neg q) \land (\neg q \To \neg p) }\ \why[\To]{ Transitividad($\To$) }\ \res{ p \To \neg p }\ \why{ Def.(alt)($\To$) }\ \res{ \neg p \lor \neg p }\ \why{ Idempotencia($\lor$) }\ \res{ \neg p } \end{derivation} \end{center} \end{document}

enter image description here

Apparently, the issue is the babel package.

DAGO
  • 67
  • 2
    I don't know enough to help you immediately, but: (1) \begingroup/\endgroup already comes with an environment, I don't think you need it. More importantly, (2) if the arguments are optional, what should happen if they're not given? Can you show us how you're trying to use them, so that they print in the pdf or give you an error? – Teepeemm Feb 19 '23 at 15:16
  • Ignore (2), I was forgetting that syntax. (3) I can't get \begin{tabular}{>{$}l<{$} >{$}l<{$}} to work, even without a new environment. What are you trying to accomplish with that part? – Teepeemm Feb 20 '23 at 02:43
  • 1
    The environment work almost the same as align. The columns in the tabular environment avoid writing $ in every line of the table. – DAGO Feb 20 '23 at 04:02
  • 1
    @DavidGómez That's just an array though ... – Joseph Wright Feb 20 '23 at 06:49
  • 1
    // When I use the method in tables - Math mode in tabular without having to use $...$ everywhere - TeX - LaTeX Stack Exchange it works well for me, although I got other errors e.g. \res is not defined. // so please write a minimal working example (See link for more details what it means) if you still need help. – user202729 Feb 20 '23 at 08:55
  • If I take a guess at how to define \res, \why, and \To, I can get your two snippets to compile without any errors. So I'll echo the request to please extend this into a minimal working example. – Teepeemm Feb 20 '23 at 22:02
  • A minimal working example starts with \documentclass and ends with \end{document}, so that we can copy/paste and see the output that you see. I get your two snippets to compile without any errors. – Teepeemm Feb 21 '23 at 14:51

1 Answers1

5

By default, babel-spanish activates < and > for quotes.

This activation is done at begin document, but your code requires LaTeX to look for “ordinary” < and >, which it cannot find.

Solution: pass the es-noquoting option.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[spanish,es-noquoting]{babel}
\usepackage{mathtools}
\usepackage{nicematrix} % loads the package 'array', used in the code

\ExplSyntaxOn \NewDocumentCommand\why{O{\equiv}m} { #1 & \quad\langle;\text{{#2}};\rangle }

\NewDocumentCommand\res{m} { & #1}

\NewDocumentCommand\To{}{\Rightarrow}

\NewDocumentEnvironment{derivation}{D<>{1.2} O{0pt}}{% \renewcommand{\arraystretch}{#1}% \setlength{\tabcolsep}{#2}% \begin{tabular}{>{$}l<{$} >{$}l<{$}}% }{ \end{tabular}% } \ExplSyntaxOff

\begin{document}

\begin{center} \begin{derivation}<1.5> \res{ (p \To \neg q) \land (\neg q \To \neg p) }\ \why[\To]{ Transitividad($\To$) }\ \res{ p \To \neg p }\ \why{ Def.(alt)($\To$) }\ \res{ \neg p \lor \neg p }\ \why{ Idempotencia($\lor$) }\ \res{ \neg p } \end{derivation} \end{center} \end{document}

I removed the call to xparse that's not needed since October 2020. Instead I added fontenc with the T1 option, which is needed for Spanish.

Check the positions of %.

enter image description here

F. Pantigny
  • 40,250
egreg
  • 1,121,712