2

I'd like to define a babel language alias, which works identically as the original for the usual language selectors, babel ones, or derived ones, such as those of csquotes and biblatex. Ideally, babel shorthands for the original language would also work for the alias. For the sake of example, let's say I want to create a myenglishalias from english.

The use case here is that my documents commonly have two variants of my native language, my own text and a number of quotations from old sources, which use old spelling. Now, so far I haven't felt the need to treat them differently for LaTeX (hyphenation etc.), however, I'd like the editor to treat them differently (namely, to use different dictionaries for spellchecking). But I have to be able to differentiate the markup, so that the editor's parsing can identify the two language variants.

Some constraints:

  • I suppose an easy way out would be to make a copy of english.ldf, rename it, and add it to my texmf tree. However, I'd like the document to be compilable in any TeX installation, not just in my computer. So this must be handled at the document level.

  • Technically, I could also just use an existing alias (there is actually one for the language of interest), but the markup would be semantically misleading. So I'd like to define a meaningful alias for the use case.

I don't know if this is possible and, if so, if it's worth it. But I'd like to consider the technical problem and assess this later. A look a the docs suggests \babelprovide is likely the tool, but as far as I could grasp, I couldn't figure how to "import everything". Or perhaps there's some other way. I'm also not sure if the languages would actually be equivalent by using \babelprovide, since the language of interest is .ldf based, and \babelprovide's import seems to import from the .ini file. But I think a "identity" is not really a strict requirement. As mentioned, the use case is for quotations, thus usually short pieces of text. As long as the alias behaves "close enough" to the original language, it'd be fine.

This is a MWE for the kind of thing I'd like to be able to achieve:

\documentclass{article}

\usepackage[english]{babel}
\usepackage{csquotes}
\usepackage{biblatex}
\addbibresource{biblatex-examples.bib}
\usepackage{lipsum}

\begin{document}

\section{Section 1}

\foreignlanguage{english}{\lipsum[1]}

\begin{otherlanguage}{english}
  \lipsum[2-4]
\end{otherlanguage}

\foreignquote{english}{\lipsum[5]}

\hyphenquote{english}{\lipsum[6]}

\foreignblockquote{english}{\lipsum[7]}

\begin{foreigndisplayquote}{english}
  \lipsum[8-10]
\end{foreigndisplayquote}

\begin{hyphendisplayquote}{english}
  \lipsum[11-13]
\end{hyphendisplayquote}

\selectlanguage{english}

\lipsum[14-16]

\cite{sigfridsson}

\printbibliography

\section{Section 2}

What I'd like to do is for the following (and similar constructs) to be valid
and work just like if ``english'' was being selected.

% \foreignlanguage{myenglishalias}{\lipsum[1]}
%
% \begin{otherlanguage}{myenglishalias}
%   \lipsum[2-4]
% \end{otherlanguage}
%
% \foreignquote{myenglishalias}{\lipsum[5]}
%
% \hyphenquote{myenglishalias}{\lipsum[6]}
%
% \foreignblockquote{myenglishalias}{\lipsum[7]}
%
% \begin{foreigndisplayquote}{myenglishalias}
%   \lipsum[8-10]
% \end{foreigndisplayquote}
%
% \begin{hyphendisplayquote}{myenglishalias}
%   \lipsum[11-13]
% \end{hyphendisplayquote}
%
% \selectlanguage{myenglishalias}
%
% \lipsum[14-16]
%
% \cite{sigfridsson}
%
% \printbibliography

\end{document}

1 Answer 1

2

Sadly, with the old good ldf mechanism it’s not possible in general, because the files intermingle the logic, the data and the user interface. Sure, they are great in monolingual documents, but in multilingual ones the ldf mechanism can be problematic. In fact, one of the reasons the ini mechanism was introduced was to provide a way to define and use languages with a more modern and strong foundation.

In most cases, the result with ini files is almost the same (or even the same) as with ldf files, and this is the case for English. With others, like French, there can be important differences (for example, spacing with «, », ?, and the like is not ‘fixed’ with the ini file [Edit. Currently babel provides this functionality in both XeLaTeX and LuaLaTeX, but it must be activated with interchar=puntuation.space or transforms=puntuation.space, respectively]). Note also with ini files there are (currently) no shorthands — if you need them, you have to define them.

So, just try with something like:

\babelprovide[import=en]{myenglishalias}

You can then redefine strings for this new locale with, say:

\setlocalecaption{myenglishalias}{contents}{Table of contents}

If this works for you, fine. If not, feel free to ask for more help to solve any issue you find.

1
  • Hi Javier, thank you very much for your answer. I was already fearing as much, but it is good to have confirmation. I had been playing with \babelprovide (with import and hyphenrules) and indeed results are close, but it can fail in devious ways. Shorthands (the actual language of interest is Brazilian Portuguese), I had to define aliases for csquotes style, biblatex language mapping etc. Also for some reason, when I did try to cover these things, the MWE did not converge, as far as I can tell, because of biblatex. So I'm starting to doubt whether this is a good idea in the end...
    – gusbrs
    Commented Sep 2, 2023 at 15:17

You must log in to answer this question.

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