1

I'm trying to get datetime2 to display a custom date in the proper regional style, either using the language setting defined through polyglossia, or by passing the language setting through datetime2 option list. No success so far.

My attempt using the polyglossia language setting:

\documentclass{article}
\usepackage{fontspec}

\usepackage{polyglossia}
\setmainlanguage{german}

\usepackage{datetime2}
\DTMsavedate{customdate}{2016-03-31}

\begin{document}
\DTMusedate{customdate}
\end{document}

The date gets displayed in the default numeric style in the form 2016-03-31.

My attempt using datetime2 option list, without relying on polyglossia:

\documentclass{article}
\usepackage{fontspec}

\usepackage[german]{datetime2}
\DTMsavedate{customdate}{2016-03-31}

\begin{document}
\DTMusedate{customdate}
\end{document}

Still no success, the date still gets displayed as 2016-03-31.

Any help pointing me in the right direction would be much appreciated.

PS: I'm compiling the document using XeTeX.

3

I could not reproduce your problem at first, your MWE returned 31. März 2016 in both pdflatex and xelatex. If you want the numeric format you can use the option useregional=numeric as below, resulting in 31/3/2016. If you don't like the / separator you can use style=ddmmyyyy which uses - as separator.

However, I could reproduce the problem when I tried a datetime2 language module that was not installed, e.g., usepackage[french]{datetime2}. Then the default style is used, i.e., yyyy-mm-dd. The package warns for this in the terminal but it does not terminate the compilation process, maybe you have missed this.

Installation is easy with tlmgr install datetime2-german for TexLive or the graphical package manager in MikTeX. Ubuntu does not (yet) have datetime2 in the repositories.

Notes:

  • xelatex may need usepackage{fontspec} (not necessary for pdflatex)
  • xetex cannot compile your MWE because it does not know usepackage
  • please include a documentclass in your MWE

Code:

\documentclass{article}
%\usepackage{fontspec}                                %%% for xelatex
\usepackage[german]{datetime2}                        %%% 31. März 2016
%\usepackage[german,useregional=numeric]{datetime2}   %%% 31/3/2016
%\usepackage[german,style=ddmmyyyy]{datetime2}        %%% 31-03-2016
\DTMsavedate{customdate}{2016-03-31}

\begin{document}
\DTMusedate{customdate}
\end{document}
  • Note that the engine is XeTeX when you compile with xelatex. On Unix-type systems, xelatex is just a symbolic link to xetex. Using xelatex just tells xetex to load the LaTeX format. That is, a rose by any other name is not always quite a sweet depending on the use to which you wish to put your rose. But the engine is just the same. – cfr Apr 24 '16 at 18:26
  • with xelatex the result is the same when using fontspec, mentioned in my answer, see also tex.stackexchange.com/questions/66676/…, I edited my MWE to make this clear. – Marijn Apr 25 '16 at 7:14
  • Yes, I found fontspec was needed here. – cfr Apr 25 '16 at 10:01
  • Thank you, added documentclass to my MWEs and got it working after installing the proper language modules. A last question: is it really impossible to get datetime2 to just pick the language setting from polyglossia and output the date in the correct format without installing additional modules? – zool Apr 25 '16 at 10:25
  • 1
    @zool You can use Polyglossia commands to get the date correctly, but if you want to use datetime2's commands, you need constructions provided on that package's own terms in its modules. The issue is not recognising the language to use as such as much as it is knowing the appropriate stuff required to format dates given that recognition. – cfr Apr 25 '16 at 10:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.