# Insert space with babel post-hyphenation

In czech, we write date ranges with en-dash without spaces, e.g.

1351–1362

It is not allowed to break the line around the dash. Instead, when necessary, it should be typeset as

1351 až 1362

where "až" means "to" or "until". Then the linebreak can occur after the word "až".

Ranges like these occur a lot in the book I'm working on. Therefore, I wish to use babel extended hyphenation rules to sort this issue out automatically.

I created a \babelposthyphenation rule for a character § that would be used instead of the endash in these cases. It works as expected except, I can't figure out how to insert a space in front of the word "až". I couldn't find the answer at the babel wiki and I don't understand the source code well enough.

Here is the result (MWE that compiles with lualatex and the latest version of babel below). The first line shows the desired result.

% !TeX encoding = UTF-8
% !TeX program = lualatex
\documentclass[10pt,twoside]{book}

\usepackage[czech]{babel}
\usepackage[papersize={85mm, 100mm},showframe]{geometry}

\babelposthyphenation{czech}{.§.}{
{},
{ no = --, pre = až, post = , data = 1 },
{}
}

\begin{document}
\thispagestyle{empty}
\noindent profesorem 1351--1362 a~v~roce 1353~až 1372

\vspace*{2ex}
\noindent profesorem 1351§1362 a~v~roce 1353§1372
\end{document}

• For the moment \babelposthyphenation deals with words only, so glues and kerns cannot be inserted. There will be a \babelprehyphenation which will allow more general transformations, but anyway I don't think this is the best way and the @egregs 's way is much better. – Javier Bezos Mar 30 at 10:53

You cannot put skips in the prebreak, postbreak and nobreak texts. You can have a kern, though. It won't participate on space stretching or shrinking in the line.

Two methods, I'd prefer the first because it carries more semantic.

\documentclass[10pt,twoside]{book}
\usepackage[czech]{babel}
\usepackage[papersize={85mm, 100mm},showframe]{geometry}
\usepackage{newunicodechar}

\newcommand{\breakrange}{\discretionary{\kern0.3333em až}{}{--}}
\newcommand{\yrrange}[2]{#1\breakrange#2}
\newunicodechar{§}{\breakrange}

\begin{document}
\thispagestyle{empty}

\noindent profesorem \yrrange{1351}{1362} a~v~roce \yrrange{1353}{1372}

\vspace*{2ex}
\noindent profesorem 1351§1362 a~v~roce 1353§1372

\end{document}


• Would "{} pre = až" work, or does that count as a skip? – barbara beeton Mar 29 at 18:27
• @egreg This works great, exactly what I was after, thanks a lot! I also like the first method better. – Ondrian Mar 29 at 18:48
• @barbarabeeton if I understood you correctly this does not work. I get Inserting Babel.hyphenate' at position 1 in hyphenate'.[\directlua]:1: '}' exp ected near 'pre'. \babelposthyphenation ...ce = { \babeltempb } }) } \endgroup – Ondrian Mar 29 at 18:54
• @Ondrian -- I'm not really familiar with the innards of babel, so the suggestion was a wild guess, Thank you for confirming that it doesn't work. This might save someone else from wasting time. I don't know whether this situation is addressed in the babel documentation , but if it isn't, it might be a nice addition. – barbara beeton Mar 29 at 19:21