The comments on @daleif's answer have become a little convoluted, so it's probably easier if I try to summarise it here as an extension to the other answer.
LaTeX's default format of \today
is the US style in the form "November 4, 2016". For example:
\documentclass{article}
\begin{document}
\today
\end{document}
The babel
package loaded with the option swedish
redefines \today
to use the Swedish form "4 november 2016":
\documentclass{article}
\usepackage[swedish]{babel}
\begin{document}
\today
\end{document}
However, you can't customise this if you want to make some slight modifications (such as have "4e" instead of just "4") and there's also no provision for formatting a specific date. The datetime2
package provides this extra functionality, but it needs to know what language you're using in your document. Luckily, datetime2
loads the tracklang
package which can find out whether babel
or polyglossia
or whatever has been used, and it can tell datetime2
what language(s) you've already requested.
So you can just do:
\documentclass{article}
\usepackage[swedish]{babel}
\usepackage[useregional=text]{datetime2}
\begin{document}
\today
\end{document}
Which produces "4 november 2016" (or you can useregional=numeric
to get a numeric date in your regional format). Thanks to the tracklang
package, datetime2
knows that it needs to load datetime2-swedish.ldf
, which provides the Swedish date styles (swedish
and swedish-numeric
). It's this datetime2-swedish.ldf
file that provides the command \DTMswedishordinal
which formats the ordinal part of the swedish
textual date style.
This can be redefined. For example:
\documentclass{article}
\usepackage[swedish]{babel}
\usepackage[useregional=text]{datetime2}
\renewcommand*{\DTMswedishordinal}[1]{\number#1e}
\begin{document}
\today
\end{document}
This produces "4e november 2016".
Other variations include specifying the language as a document class option:
\documentclass[swedish]{article}
\usepackage{babel}
\usepackage[useregional=text]{datetime2}
\renewcommand*{\DTMswedishordinal}[1]{\number#1e}
\begin{document}
\today
\end{document}
In fact, datetime2
can be used without babel
. For example
\documentclass{article}
\usepackage[swedish]{datetime2}
\renewcommand*{\DTMswedishordinal}[1]{\number#1e}
\begin{document}
\today
\end{document}
Things that can go wrong:
- The package loading is in the wrong order. If
babel
is loaded after datetime2
instead of before, it's too late for datetime2
to override babel
's date hook. It's also too late to pick up the required language unless it's been passed as a document class option or directly to datetime2
.
The class or another package might try redefining \today
at the start of the document. For example, the following mimics a class that does this:
\AtBeginDocument{\def\today{\ifcase\month\or January\or February\or March\or
April\or May\or June\or July\or August\or September\or October\or
November\or December\fi \space \number \day, \number \year}}
\documentclass{article}
\usepackage[swedish]{babel}
\usepackage[useregional=text]{datetime2}
\renewcommand*{\DTMswedishordinal}[1]{\number#1e}
\begin{document}
\today
\end{document}
This now produces "November 4, 2016" because of the redefinition in \AtBeginDocument
.
There's also the possibility that another package loaded after datetime2
does something similar. To provide a way to counteract this, datetime2
provides \DTMtoday
(new to version 1.4) which is datetime2
's version of \today
. You can use it directly or redefine \today
at the beginning of the document:
\AtBeginDocument{\def\today{\ifcase\month\or January\or February\or March\or
April\or May\or June\or July\or August\or September\or October\or
November\or December\fi \space \number \day, \number \year}}
\documentclass{article}
\usepackage[swedish]{babel}
\usepackage[useregional=text]{datetime2}
\renewcommand*{\DTMswedishordinal}[1]{\number#1e}
\begin{document}
\DTMtoday
\end{document}
This produces "4e november 2016", even though \today
is back to the original US style. Alternatively:
\AtBeginDocument{\def\today{\ifcase\month\or January\or February\or March\or
April\or May\or June\or July\or August\or September\or October\or
November\or December\fi \space \number \day, \number \year}}
\documentclass{article}
\usepackage[swedish]{babel}
\usepackage[useregional=text]{datetime2}
\renewcommand*{\DTMswedishordinal}[1]{\number#1e}
\begin{document}
\let\today\DTMtoday
\today
\end{document}
If you have an old version of datetime2
that doesn't recognise \DTMtoday
, then you can save and restore datetime2
's version of \today
like this:
\AtBeginDocument{\def\today{\ifcase\month\or January\or February\or March\or
April\or May\or June\or July\or August\or September\or October\or
November\or December\fi \space \number \day, \number \year}}
\documentclass{article}
\usepackage[swedish]{babel}
\usepackage[useregional=text]{datetime2}
\let\dtmtoday\today
\renewcommand*{\DTMswedishordinal}[1]{\number#1e}
\begin{document}
\let\today\dtmtoday
\today
\end{document}
It turns out the problem is because your class file temp.cls
is loading babel
with english
. This means that the main document language is English not Swedish so you effectively have a situation analogous to:
\documentclass[swedish]{article}
\usepackage[english]{babel}
\begin{document}
\today
\end{document}
This sets the main language to english
with swedish
as an auxiliary language. You can override this by inserting the following line before the document class is loaded:
\PassOptionsToPackage{main=swedish}{babel}
This will ensure that babel
recognises that swedish
is the main document language.
temp
article
class instead oftemp
. It is a lot easier to make examples fro others when you use a setup that others can understand. Alsodatetime2-swedish
is not a latex package, it is a configuration fordatetime2
, it is used whendatetime2
detects that it needs to use swedish lanuage, for example like in my MWE