5

I am using XeLaTeX and the fontspec package to work with text that uses UTF-8 interpuncts (·) instead of spaces.

However, interpuncts are not understood by 'TeX to be spacing characters, and so long lines of text using interpuncts overflow the page boundary.

Example:

\documentclass[openany]{book}
\usepackage{fontspec}

\begin{document}
Lorem·ipsum·lorem·ipsum·lorem·ipsum·lorem·ipsum·lorem·ipsum·lorem·ipsum·lorem·ipsum·lorem·ipsum·lorem·ipsum·lorem·ipsum·lorem·ipsum·lorem·ipsum·lorem·ipsum·lorem·ipsum·lorem·ipsum·lorem...
\end{document}

I know that the seqsplit package exists, but that seems to be more for splitting long strings at wrapping boundaries (DNA/RNA transcription) rather than splitting in cases like this.

Two inter-related questions:

  • Is there a package or command that could be used to define the interpunct character generally as a spacing character?
  • Would it be possible to eliminate the interpunct character when wrapping occurs? That is, the line wrap replaces the need for the interpunct character.

(Note: I am using interpunct characters only as spaces, not for any of the other common usages of interpuncts, so this solution can break other usages of interpuncts.)

1 Answer 1

5

A variation on https://tex.stackexchange.com/a/44951/4427 (see there for attributions).

\documentclass{article}
\usepackage{fontspec}
\usepackage{newunicodechar}

\newcommand{\spaceinterpunct}{\unskip
  \hskip 2pt plus 1pt minus 1pt
  \cleaders\copy\interpunctbox\hskip\wd\interpunctbox
  \hskip 2pt plus 1pt minus 1pt
  \ignorespaces}
\newsavebox\interpunctbox
\sbox\interpunctbox{·}

\newunicodechar{·}{\spaceinterpunct}

\begin{document}

Nulla·malesuada·porttitor·diam.·Donec·felis·erat,·congue·non,·volutpat·at,·tincidunt·tristique,·libero.·Vivamus·viverra·fermentum·felis.·Donec·nonummy·pellentesque·ante.·Phasellus·adipiscing·semper·elit.·Proin·fermentum·massa·ac·quam.·Sed·diam·turpis,·molestie·vitae,·placerat·a,·molestie·nec,·leo.·Maecenas·lacinia.·Nam·ipsum·ligula,·eleifend·at,·accumsan·nec,·suscipit·a,·ipsum.·Morbi·blandit·ligula·feugiat·magna.·Nunc·eleifend·consequat·lorem.·Sed·lacinia·nulla·vitae·enim.·Pellentesque·tincidunt·purus·vel·magna.·Integer·non·enim.·Praesent·euismod·nunc·eu·purus.·Donec·bibendum·quam·in·tellus.·Nullam·cursus·pulvinar·lectus.·Donec·et·mi.·Nam·vulputate·metus·eu·enim.·Vestibulum·pellentesque·felis·eu·massa.

\end{document}

enter image description here

You can even break lines (after or before the interpunct, it doesn't matter. The following code with line breaks will produce the same output.

Nulla·malesuada·porttitor·diam.·Donec·felis·erat,·
congue·non,·volutpat·at,·tincidunt·tristique,·libero.·
Vivamus·viverra·fermentum·felis.·Donec·nonummy·
pellentesque·ante.·Phasellus·adipiscing·semper·elit.·
Proin·fermentum·massa·ac·quam.·Sed·diam·turpis,·
molestie·vitae,·placerat·a,·molestie·nec,·leo.·
Maecenas·lacinia.·Nam·ipsum·ligula,·eleifend·at,·
accumsan·nec,·suscipit·a,·ipsum.·Morbi·blandit·
ligula·feugiat·magna.·Nunc·eleifend·consequat·
lorem.·Sed·lacinia·nulla·vitae·enim.·Pellentesque·
tincidunt·purus·vel·magna.·Integer·non·enim.·
Praesent·euismod·nunc·eu·purus.·Donec·bibendum·
quam·in·tellus.·Nullam·cursus·pulvinar·lectus.·
Donec·et·mi.·Nam·vulputate·metus·eu·enim.·
Vestibulum·pellentesque·felis·eu·massa.
1
  • That work's great! I would've never found the linked question, so thanks for that as well.
    – nitelich
    Jun 20, 2021 at 0:09

You must log in to answer this question.

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