# How to display specified date from numeric value to Lithuanian format?

I'm unable to understand how to specify a date something like 06-09-2012 (or any other numeric equivalent) so it would print it in Lithuanian? There's package called [lithuanian]{babel} and for example \today works fine. But I don't need today's date, I need specific date which would be converted to \longdate format and translated to Lithuanian. I've tried various variants, sometimes it says that there's no weekday and month defined for Lithuanian language. But why \today works? If it's really true, so then how can I add those weekdays manually in my document, without hacking library itself?

• datetime doesn't provide any support for Lithuanian and as datetime is no longer maintained, no new languages will be added to it. A better option is to switch to datetime2 and add your own Lithuanian module, which can be done without hacking the base package. There's information on how to do this in the datetime2 manual near the end of the section "Multi-lingual Support". The simplest method is to just adapt an existing language module that closest matches the Lithuanian format. – Nicola Talbot Apr 29 '16 at 9:30

But why \today works?

In the kernel and with packages like babel or polyglossia, \today is hard-coded using \day (the current day of month) \month (the current month number) and \year (the year). For example, the default definition is

\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


A cheap hack is to temporarily redefine \day, \month and \year if you want a specific date. For example:

\documentclass{article}

\usepackage{polyglossia}
\setmainlanguage{lithuanian}

\newcommand*{\anotherday}[3]{%
{% scope
\def\year{#1}%
\def\month{#2}%
\def\day{#3}%
\today
}%
}

\begin{document}
\anotherday{1999}{12}{31}

\today

\end{document}


This won't work in contexts where the date needs expanding. For example, in PDF bookmarks (if you're using hyperref) or if you want to write a date stamp to an external file. It would also need protection in a moving argument.

Ideally, it's better for \today to use a date formatting command that takes the day, month and year as arguments. This formatting command could then be used for specific dates. The datetime package does this by robustly redefining \today as:

\formatdate{\day}{\month}{\year}


Whereas datetime2 does this by non-robustly redefining \today as:

\DTMdisplaydate{\@dtm@currentyear}{\@dtm@currentmonth}{\@dtm@currentday}{\@dtm@currentdow}


This doesn't use \year, \month and \day, but instead uses its own internal storage commands, including the day of week index (which defaults to -1, but the datetime2-calc package will compute it using commands provided by pgfcalendar).

In the case of datetime, the formatting command \formatdate is redefined by the date styles. The language styles are provided in the files dt-language.def. The provided .def files are:

dt-american.def    dt-croatian.def   dt-greek.def       dt-ngerman.def   dt-slovene.def
dt-australian.def  dt-czech.def      dt-hebrew.def      dt-norsk.def     dt-spanish.def
dt-austrian.def    dt-danish.def     dt-icelandic.def   dt-polish.def    dt-swedish.def
dt-bahasa.def      dt-dutch.def      dt-irish.def       dt-portuges.def  dt-turkish.def
dt-basque.def      dt-esperanto.def  dt-italian.def     dt-romanian.def  dt-UKenglish.def
dt-breton.def      dt-estonian.def   dt-latin.def       dt-russian.def   dt-ukraineb.def
dt-british.def     dt-finnish.def    dt-lsorbian.def    dt-samin.def     dt-USenglish.def
dt-bulgarian.def   dt-french.def     dt-magyar.def      dt-scottish.def  dt-usorbian.def
dt-catalan.def     dt-german.def     dt-newzealand.def  dt-slovak.def


This doesn't include a file for Lithuanian. Adding a new supported language requires not only a new .def file but also a modification to datetime.sty.

The datetime2 package, which replaces datetime, also uses styles to redefine \DTMdisplaydate. There are some numeric styles available in the base datetime2.sty code, but the language and regional styles are provided in independently maintained .ldf files. Unlike datetime, the .ldf files can be added without any modification to the base datetime2.sty code. This makes it easier for users to add support for their own language or region. A search of CTAN will list all supported languages.

If your language isn't supported, here are some instructions on how to add it.

There are two basic types of datetime2 .ldf files:

• Regionless language-only support. For example, datetime2-scottish, which only provides the date styles scottish and scottish-numeric.
• Support for a particular combination of language and region. For example, datetime2-english, which provides the regionless english style (matches the kernel definition of \today) but also a number of regional styles. At the time of writing these are:

• en-GB (English - United Kingdom of Great Britain and Northern Ireland)
• en-US (English - United States of America)
• en-CA (English - Canada)
• en-AU (English - Commonwealth of Australia)
• en-NZ (English - New Zealand)
• en-GG (English - Bailiwick of Guernsey)
• en-JE (English - Bailiwick of Jersey)
• en-IM (English - Isle of Man)
• en-MT (English - Republic of Malta)
• en-IE (English - Republic of Ireland)

These not only change the way \DTMdisplaydate behaves but also set the time zone mappings. For example, the en-GB style displays UTC+1 as BST whereas the en-IE style displays it as IST when the time zone mappings are on.

The date styles provided for languages with extended Latin or non-Latin characters have two versions: language-ascii.ldf and language-utf8.ldf. The ascii version uses LaTeX commands, such as \', to produce the non-ASCII characters. The utf8 version uses UTF-8 characters. This means that XeLaTeX or LuaLaTeX users can conveniently write the date to an external non-TeX file in an easy to read format.

Some styles may also provide different alphabets. For example, datetime2-serbian has Cyrillic and Latin options and provides \DTMserbiancyrmonthname for the Cyrillic month names and \DTMserbianlatinmonthname for the Latin month names. The default month names are provided by \DTMserbianmonthname which is initialised to \DTMserbiancyrmonthname. The alphabet setting redefines \DTMserbianmonthname.

If you want to provide support for a new language, the simplest thing is to find an existing style and modify it as appropriate.

For example, I'm going to base it on the german style (because that has UTF-8 support) with some modifications. So download datetime2-german.dtx and save it as datetime2-lithuanian.dtx, download datetime2-german.ins and save it as datetime2-lithuanian.ins and download README.

In each of these three files, do the following case-sensitive global search and replace (make sure your editor is set to UTF-8):

• german -> lithuanian
• German -> Lithuanian

(If you want to upload it to CTAN, which would be helpful to others, then change the version number and dates as appropriate, as well as the maintainer's name and the documentation. Make sure you set the line endings to LF.)

In the file datetime2-lithuanian.dtx, search for <*datetime2-lithuanian-utf8.ldf>. This is the start of the UTF-8 support. The first command is

\newcommand*{\DTMlithuanianordinal}[1]{%
\number#1
}


This is the way the day of month number is displayed. I don't know any Lithuanian, but I'm guessing from the way polyglossia displays the date that this should be \number#1~d. so make the appropriate change here.

Is the m. part of the month name or a year suffix? If it's a year suffix, add

%\begin{macro}{\DTMlithuanianyear}
%    \begin{macrocode}
\newcommand*{\DTMlithuanianyear}[1]{%
\number#1 m.%
}
%    \end{macrocode}
%\end{macro}


otherwise it goes in the next command, which is \DTMlithuanianmonthname. Replace the month names as appropriate using UTF-8 characters. There is also a version \DTMlithuanianMonthname where the first letter is in upper case. This is in case the month needs to be displayed at the start of a sentence. Replace the month names as appropriate.

If you want to support week day names, you also need \DTMlithuanianweekdayname. This should be in the form (replace the English names with the appropriate translations):

%\begin{macro}{\DTMlithuanianweekdayname}
% Day of week names.
%    \begin{macrocode}
\newcommand*{\DTMlithuanianweekdayname}[1]{%
\ifcase#1
Monday%
\or
Tuesday%
\or
Wednesday%
\or
Thursday%
\or
Friday%
\or
Saturday%
\or
Sunday%
\fi
}
%    \end{macrocode}
%\end{macro}


Similarly provide \DTMlithuanianWeekdayname for the first letter upper case variant.

If you want to provide support for abbreviations, similarly define \DTMlithuanianshortmonthname, \DTMlithuanianshortMonthname, \DTMlithuanianshortweekdayname and \DTMlithuanianshortWeekdayname.

The next section of the .dtx file is <*datetime2-lithuanian-ascii.ldf>. Do the same as the above, but use LaTeX commands instead of UTF-8 characters.

The next section is <*datetime2-lithuanian.ldf> which provides the new date styles. There are two styles: a textual style called lithuanian and a numeric style called lithuanian-numeric. This first provides some commands that allow the styles to be configurable within \DTMlangsetup. These will need changing to match your language's style. For example, the separator between the month and day in the textual style can be defined as:

\newcommand*{\DTMlithuanianmonthdaysep}{%
\DTMtexorpdfstring{\protect~}{\space}%
}


and the corresponding key for \DTMlangsetup is defined using:

\DTMdefkey{lithuanian}{monthdaysep}{\renewcommand*{\DTMlithuanianmonthdaysep}{#1}}


Boolean settings are defined using \DTMdefboolkey. For example:

\DTMdefboolkey{lithuanian}{showdayofmonth}[true]{}


and they can be set using \DTMsetbool. For example:

\DTMsetbool{lithuanian}{showdayofmonth}{true}


The actual styles are defined using \DTMnewstyle. These need to redefine \DTMdisplaydate and (for the start of a sentence) \DTMDisplaydate. These both have four arguments: the year (##1), the month number (##2), the day of month number (##3) and the day of week index (##4).

If you have defined \DTMlithuanianyear this needs to be applied to the year. For example:

\DTMlithuanianyear{##1}%


Otherwise, just use \number:

\number##1 % space intended


The boolean keys can be accessed using \DTMifbool. For example, to determine whether or not the day of the month should be displayed:

 \DTMifbool{lithuanian}{showdayofmonth}
{\DTMlithuanianmonthdaysep\DTMlithuanianordinal{##3}}%
{}%


The global showdow setting can be queried using \ifDTMshowdow if you want to provide week day name support. Note that if the day of week index is set to -1, then the week day name should be omitted regardless of the showdow setting. For example, the en-GB style in datetime2-english.dtx has:

 \ifDTMshowdow
\ifnum##4>-1
\DTMifbool{en-GB}{abbr}%
{\DTMenglishshortweekdayname{##4}}%
{\DTMenglishweekdayname{##4}}%
\DTMenGBdowdaysep
\fi
\fi


This queries the showdow setting (\ifDTMshowdow), and then it checks that the week day index is non-negative (\ifnum##4>-1). This includes support for the abbreviated names. The boolean abbr key can be defined with:

\DTMdefboolkey{lithuanian}{abbr}[true]{}
\DTMsetbool{lithuanian}{abbr}{false}


and the separator between the week day name and the day of month number:

\newcommand*{\DTMlithuaniandowdaysep}{\space}


So the Lithuanian code would include

 \ifDTMshowdow
\ifnum##4>-1
\DTMifbool{lithuanian}{abbr}%
{\DTMlithuanianshortweekdayname{##4}}%
{\DTMlithuanianweekdayname{##4}}%
\DTMlithuaniandowdaysep
\fi
\fi


(Naturally you'll need to modify this if the week day name should come after the day of month number.)

Once you have made all the relevant changes, the .ldf files can be extracted using:

latex datetime2-lithuanian.ins


For the documented code use:

pdflatex datetime2-lithuanian.dtx


Use a code like this.

\documentclass{article}

\usepackage[lithuanian]{babel}

\usepackage{datetime}

\begin{document}

Date in long format so that language variations are prominent.

Today's date: \today.

Now, let us set a new date.

\newdate{ld}{6}{9}{2012}

And display it.

\displaydate{ld}

\end{document}

• Thanks for patience @Masroor. In the end it displays: "Thursday 6 September, 2012", although today's date shows in Lithuanian. After documentclass, I've added \usepackage[L7x]{fontenc} or else it says Error: Encoding scheme L7x unknown. I'm using TeXnicle app with MacTex 5gb installation :) – holms Feb 29 '16 at 4:34