5

It seems that the datetime2 and the nccmath packages are incompatible when I load the [useregional] option in the first (I get command \nr already defined).

I used a solution for reducing spacing around my equations that needed the latter, and I suppose I could find another one just as easily (even though maybe not as convenient), but maybe someone here could find a way to fix this.

MWE:

\documentclass{article}

\usepackage[useregional]{datetime2}
\usepackage{nccmath}
\usepackage{lipsum}

\title{Example}
\author{Isabella B.}

\begin{document}
    \maketitle

    \lipsum[1]

    \useshortskip

    \[ 2\times2=4 \]

    \lipsum[1]
\end{document}

enter image description here

The nccmath \useshortskip command still works, but maybe some other functionality is being compromised.

With \useshortskip:

enter image description here

Without \useshortskip:

enter image description here

2

2 Answers 2

5

Yes, they have a small incompatibility. The nccmath defines \nr to be equivalent to \\[0.5ex]. If you will not use this shortcut, then the solution proposed by @Zarko will work: nccmath will define \nr and datetime2 will overwrite it without problems.

But if you would like to have the \nr shortcut then that won't work. datetime2 uses \nr as a temporary macro to hold a number. You can redefine that to use another name, so the clash doesn't happen. Add this to your preamble after loading datetime2 and before nccmath:

\makeatletter
\define@choicekey{datetime2.sty}{useregional}[\DTM@val\DTM@nr]%
 {false,text,numeric,num}[text]%
 {%
   \ifcase\DTM@nr\relax
     \renewcommand*{\DTMifcaseregional}[3]{##1}%
   \or
     \renewcommand*{\DTMifcaseregional}[3]{##2}%
   \or
     \renewcommand*{\DTMifcaseregional}[3]{##3}%
   \or
     \renewcommand*{\DTMifcaseregional}[3]{##3}%
   \fi
 }
\let\nr\relax
\makeatother

MWE:

\documentclass{article}

\usepackage[useregional]{datetime2}
\makeatletter
\define@choicekey{datetime2.sty}{useregional}[\DTM@val\DTM@nr]%
 {false,text,numeric,num}[text]%
 {%
   \ifcase\DTM@nr\relax
     \renewcommand*{\DTMifcaseregional}[3]{##1}%
   \or
     \renewcommand*{\DTMifcaseregional}[3]{##2}%
   \or
     \renewcommand*{\DTMifcaseregional}[3]{##3}%
   \or
     \renewcommand*{\DTMifcaseregional}[3]{##3}%
   \fi
 }
\let\nr\relax
\makeatother
\usepackage{nccmath}
\usepackage{lipsum}

\title{Example}
\author{Isabella B.}

\begin{document}
    \maketitle

    \lipsum[1]

    \useshortskip

    \[ 2\times2=4 \]

    \lipsum[1]
\end{document}
5
  • 1
    The usage of \nr stems from examples in the manual of xkeyval (see page 6); it's wrong: a scratch macro used by a package should always have @ in its name. On the other hand, I have no clue as to why nccmath chose the name \nr for \\[0.5ex].
    – egreg
    Oct 19, 2019 at 17:16
  • 1
    I filed a bug report. By the way, also \val should be changed in, say, \DTM@val
    – egreg
    Oct 19, 2019 at 17:33
  • @egreg Thank you for your comments. Now I understand why these macro names were used. I am going fix \val in my answer.
    – LaTeXer
    Oct 19, 2019 at 18:31
  • 1
    It turns out that the optional argument to \define@choicekey should consist of two tokens that are used as scratch macros. Neither \val nor \nr appear in the package code; when checking with \tracingmacros=1, I found that the code does \def\val{...}, where \val is absorbed as the first argument to a macro, the second argument, in the example case is \nr that receives various integer values according to the number of items in the following argument.
    – egreg
    Oct 19, 2019 at 22:18
  • @egreg Oh, I think I get it. For example, \val would be text, and then \nr would be 1 (which is then used in the \ifcase). So the name of these two macros don't really matter as long as they are the same as in the code of the option... After your comment I tried to understand the code in xkeyval but I got lost after the 7th or 8th variation of \XKV@d@f@ne@ch@ic@k@y XD
    – LaTeXer
    Oct 19, 2019 at 22:35
4

You can load packages in this order, neutralising the \nr command from nccmath:

\usepackage{nccmath}%
\let\nr\relax%
\usepackage[useregional]{datetime2}

You can replace the nccmath \nr either with what it's for: \\[0.5ex], or use the linespread environment from mathtools (needless to load amsmath in this case).

2
  • 1
    That's what @Zarko said in the comment and I in my answer. Perhaps \let\NCnr\nr\let\nr\relax to preserve the \nr command somewhere...
    – LaTeXer
    Oct 19, 2019 at 14:06
  • Excellent suggestion!
    – Bernard
    Oct 19, 2019 at 14:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .