7

I wanted to reduce the inter-word space for some passages in a written text with the rest of the text remaining unchanged. So I tried to use \addfontfeature locally which I execute with the command \tight{bla}

The issue now is that everything after the \addfontfeature is also affected by it. Even when I add a second \addfontfeature (executed by \nottight{bla}) to reverse the effect, I get the same result.

What am I doing wrong?

MWE:

% !TEX TS-program = LuaLaTeX
\documentclass{scrartcl}

\usepackage{fontspec}
\setmainfont{Arial Unicode MS}

\newfontfamily\arabicfont[Script=Arabic,Numbers=Arabic]{Arial Unicode MS}
\newcommand{\arabtext}[1]       % Arabic inside LTR
    {\bgroup\luatextextdir TRT\arabicfont{#1}\hfill\egroup}

\newcommand{\tight}[1]
    {\bgroup\addfontfeature{WordSpace=-2.0}#1\egroup}
\newcommand{\nottight}[1]
    {\bgroup\addfontfeature{WordSpace=1.0}#1\egroup}

\begin{document}

% normal text:
Lorem ipsum dolor sit amet, vel ei ipsum animal. Sea intellegat interpretaris no. Vis id summo periculis, ut duo falli recteque. Id sea gubergren splendide repudiandae. Quo tota quaeque conclusionemque.

% tight text:
\tight{Lorem ipsum dolor sit amet, vel ei ipsum animal. Sea intellegat interpretaris no. Vis id summo periculis, ut duo falli recteque. Id sea gubergren splendide repudiandae. Quo tota quaeque conclusionemque.}

% should be normal text:
\nottight%
Lorem ipsum dolor sit amet, vel ei ipsum animal. Sea intellegat interpretaris no. Vis id summo periculis, ut duo falli recteque. Id sea gubergren splendide repudiandae. Quo tota quaeque conclusionemque.}

% normal Arabic text:
\arabtext{وفي تشكيل الأمور ما, عُقر حادثة أصقاع عدم تم, دون واحدة فهرست بـ. أن بوابة ا الوزراء كلا. و إختار بمحاولة فقد, ذات أمّا مواقعها ان. إنطلاق المؤلّفة اليابان، تم.}

% tight Arabic text:
\arabtext{\tight{وفي تشكيل الأمور ما, عُقر حادثة أصقاع عدم تم, دون واحدة فهرست بـ. أن بوابة ا الوزراء كلا. و إختار بمحاولة فقد, ذات أمّا مواقعها ان. إنطلاق المؤلّفة اليابان، تم.}}

% should be normal Arabic text:
\arabtext{\nottight%
وفي تشكيل الأمور ما, عُقر حادثة أصقاع عدم تم, دون واحدة فهرست بـ. أن بوابة ا الوزراء كلا. و إختار بمحاولة فقد, ذات أمّا مواقعها ان. إنطلاق المؤلّفة اليابان، تم.}

\end{document}
9
  • 1
    Did you try with an environment instead of a command? – Bernard Jul 19 '15 at 14:44
  • I tried \newenvironment{tighter}[1]{\addfontfeature{WordSpace=-2.0}#1}{\addfontfeature{WordSpace=1.0}} with the same result. However, I would prefer an option where I can have different inter-word spaces within one line or paragraph, e.g. "bla bla bla \tight{foo bar foo bar} bla bla bla" with "bla bla" having normal space and "foo bar" tighter space. – ClintEastwood Jul 19 '15 at 14:59
  • 2
    Wow, WordSpace is pretty underdescribed, though I guess it is an additive feature (or, here, multplicative..?). To reverse your change, try using the setting -0.5. Caveat: apparently really wishing one could read Arabic isn't enough to actually read Arabic. – jon Jul 19 '15 at 15:38
  • @jon : That works. But since I chose -2.0 randomly to make the effect visible, I need to ask you now how you calculated -0.5? Or generally: what would be the value for the reverse command given any random value for the initial command? – ClintEastwood Jul 19 '15 at 15:59
  • @jon : oh yes, now I understand what you meant by "multiplicative feature"... thanks – ClintEastwood Jul 19 '15 at 16:01
5

Rather than WordSpace, you should use \spaceskip, which respects grouping. The problems is that WordSpace=... sets \fontdimen parameters and these assignments are global (affecting the current font only, though).

\documentclass{scrartcl}

\usepackage{fontspec}
\setmainfont{Arial Unicode MS}

\newfontfamily\arabicfont[Script=Arabic,Numbers=Arabic]{Arial Unicode MS}
\newcommand{\arabtext}[1]       % Arabic inside LTR
    {\bgroup\luatextextdir TRT\arabicfont{#1}\hfill\egroup}

\newcommand{\tight}[1]
    {\bgroup\spaceskip=0.2pt plus 0.2pt minus 0.1pt\relax#1\egroup}

\begin{document}

% normal text:
Lorem ipsum dolor sit amet, vel ei ipsum animal. Sea intellegat interpretaris no. Vis id summo periculis, ut duo falli recteque. Id sea gubergren splendide repudiandae. Quo tota quaeque conclusionemque.

% tight text:
\tight{Lorem ipsum dolor sit amet, vel ei ipsum animal. Sea intellegat interpretaris no. Vis id summo periculis, ut duo falli recteque. Id sea gubergren splendide repudiandae. Quo tota quaeque conclusionemque.}

% should be normal text:
Lorem ipsum dolor sit amet, vel ei ipsum animal. Sea intellegat interpretaris no. Vis id summo periculis, ut duo falli recteque. Id sea gubergren splendide repudiandae. Quo tota quaeque conclusionemque.

% normal Arabic text:
\arabtext{وفي تشكيل الأمور ما, عُقر حادثة أصقاع عدم تم, دون واحدة فهرست بـ. أن بوابة ا الوزراء كلا. و إختار بمحاولة فقد, ذات أمّا مواقعها ان. إنطلاق المؤلّفة اليابان، تم.}

% tight Arabic text:
\arabtext{\tight{وفي تشكيل الأمور ما, عُقر حادثة أصقاع عدم تم, دون واحدة فهرست بـ. أن بوابة ا الوزراء كلا. و إختار بمحاولة فقد, ذات أمّا مواقعها ان. إنطلاق المؤلّفة اليابان، تم.}}

% should be normal Arabic text:
\arabtext{%
وفي تشكيل الأمور ما, عُقر حادثة أصقاع عدم تم, دون واحدة فهرست بـ. أن بوابة ا الوزراء كلا. و إختار بمحاولة فقد, ذات أمّا مواقعها ان. إنطلاق المؤلّفة اليابان، تم.}

\end{document}

enter image description here

See this answer for information about \spaceskip

2
  • that is interesting. could you briefly comment on what the line \spaceskip=0.2pt plus 0.2pt minus 0.1pt does exactly? i.e. how it should be "read"? – ClintEastwood Jul 20 '15 at 13:31
  • 1
    @ClintEastwood It sets the interword space: in this case the optimal space is 0.2pt, optimally stretched up to 0.4pt and shrunk at most to 0.1pt. See tex.stackexchange.com/a/65068/4427 – egreg Jul 20 '15 at 14:30
4

There's another way to do this: just declare a new font family for the tight spaced text. For some reason the simple version works with the latin script but fails with the Arabic script. I don't know why. To solve the Arabic script problem I've used the trick described here: Scope of \addfontfeature.

With this solution, you don't need a \nottight command at all. For the Arabic text, I've added an optional [tight] argument to the command; for the non-Arabic text I've just created a regular \tight macro.

I've used large values of the spacing parameter so that the effect is clear (of course this makes the semantics of 'tight' somewhat wonky...).

% !TEX TS-program = LuaLaTeX
\documentclass{scrartcl}

\usepackage{fontspec}
\setmainfont[BoldFont={Arial Bold}]{Arial Unicode MS}

\newfontfamily\arabicfont[Script=Arabic,Numbers=Arabic]{Arial Unicode MS}
\newfontfamily\tightarabicfont[Script=Arabic,Numbers=Arabic,WordSpace=4,Scale=.999]{Arial Unicode MS}
\newfontfamily\tightfont[WordSpace=4]{Arial Unicode MS}
\newcommand{\arabtext}[2][]% Arabic inside LTR
    {\bgroup\luatextextdir TRT{\csname #1arabicfont\endcsname #2\hfill}\egroup}

\DeclareTextFontCommand{\tight}{\tightfont}

\begin{document}

\textbf{Some normal text}

% normal text:
Lorem ipsum dolor sit amet, vel ei ipsum animal. Sea intellegat interpretaris no. Vis id summo periculis, ut duo falli recteque. Id sea gubergren splendide repudiandae. Quo tota quaeque conclusionemque.

\textbf{Some ‘tight’ (in fact expanded to show the effect) text}

% tight text:
\tight{Lorem ipsum dolor sit amet, vel ei ipsum animal. Sea intellegat interpretaris no. Vis id summo periculis, ut duo falli recteque. Id sea gubergren splendide repudiandae. Quo tota quaeque conclusionemque.}

\textbf{And back to normal} 

% should be normal text:
Lorem ipsum dolor sit amet, vel ei ipsum animal. Sea intellegat interpretaris no. Vis id summo periculis, ut duo falli recteque. Id sea gubergren splendide repudiandae. Quo tota quaeque conclusionemque.

\textbf{Now some normal Arabic text}

% normal Arabic text:
\arabtext{وفي تشكيل الأمور ما, عُقر حادثة أصقاع عدم تم, دون واحدة فهرست بـ. أن بوابة ا الوزراء كلا. و إختار بمحاولة فقد, ذات أمّا مواقعها ان. إنطلاق المؤلّفة اليابان، تم.}

\textbf{Some ‘tight’ (expanded to show the effect) Arabic text}

% tight Arabic text:
{
\arabtext[tight]{وفي تشكيل الأمور ما, عُقر حادثة أصقاع عدم تم, دون واحدة فهرست بـ. أن بوابة ا الوزراء كلا. و إختار بمحاولة فقد, ذات أمّا مواقعها ان. إنطلاق المؤلّفة اليابان، تم.}
}

\textbf{Some normal Arabic text}

% normal Arabic text:
\arabtext{وفي تشكيل الأمور ما, عُقر حادثة أصقاع عدم تم, دون واحدة فهرست بـ. أن بوابة ا الوزراء كلا. و إختار بمحاولة فقد, ذات أمّا مواقعها ان. إنطلاق المؤلّفة اليابان، تم.}

\end{document}

enter image description here

1

I think it might be better to wrap do and undo the \addfontfeature in the same command. The problem is figuring out what you needs to be undone. If you set WordSpace to -2.0, then reversing it is achieved by subsequently "setting" it to -0.5 (my rudimentary math skills suggest: -2 * -0.5 = 1...). Of course, the true values are not whole numbers, but you get the idea.

Notice how the \nottight command will only "work" (with these settings) when it directly follows a \tight command since it is designed to "multiply away" the \tight settings.

(Also: I did not have your fonts, so I switched them.)

% !TEX TS-program = LuaLaTeX
\documentclass{scrartcl}

\usepackage{fontspec}
\setmainfont{Linux Libertine O}%{Scheherazade}%{Arial Unicode MS}

\newfontfamily\arabicfont[Script=Arabic,Numbers=Arabic]{Amiri}
\newcommand{\arabtext}[1]       % Arabic inside LTR
    {\bgroup\luatextextdir TRT\arabicfont{#1}\hfill\egroup}


\newcommand{\tight}[1]
    {%
      {\bgroup\addfontfeature{WordSpace=-2}%
        #1\egroup}
      \addfontfeature{WordSpace={-0.5}}
}

\newcommand{\nottight}[1]% will fail ... except when it directly follows a "-2" change
{\bgroup\addfontfeature{WordSpace={-0.5}}%
  #1\egroup}

\begin{document}

% normal text:
\the\fontdimen2\font\quad
\the\fontdimen3\font\quad
\the\fontdimen4\font\par
Lorem ipsum dolor sit amet, vel ei ipsum animal. Sea intellegat interpretaris no. Vis id summo periculis, ut duo falli recteque. Id sea gubergren splendide repudiandae. Quo tota quaeque conclusionemque.


% tight text:
\tight{%
  \the\fontdimen2\font\quad
  \the\fontdimen3\font\quad
  \the\fontdimen4\font\par
  Lorem ipsum dolor sit amet, vel ei ipsum animal. Sea intellegat
  interpretaris no. Vis id summo periculis, ut duo falli recteque. Id
  sea gubergren splendide repudiandae. Quo tota quaeque
  conclusionemque.}


% normal text again:
\the\fontdimen2\font\quad
\the\fontdimen3\font\quad
\the\fontdimen4\font\par
Lorem ipsum dolor sit amet, vel ei ipsum animal. Sea intellegat
interpretaris no. Vis id summo periculis, ut duo falli recteque. Id
sea gubergren splendide repudiandae. Quo tota quaeque conclusionemque.


% tight in normal text
Lorem ipsum dolor sit amet, vel ei ipsum animal. Sea intellegat
interpretaris \tight{TIGHT: no.%
  \footnote{\the\fontdimen2\font\quad \the\fontdimen3\font\quad
    \the\fontdimen4\font.\quad \leftarrow\quad ``footnotesize''\ldots} %
Vis id summo periculis, ut} NOT TIGHT: duo falli recteque. Id sea gubergren
splendide repudiandae. Quo tota quaeque conclusionemque.


% won't be normal text:
\nottight{%
  \the\fontdimen2\font\quad
  \the\fontdimen3\font\quad
  \the\fontdimen4\font\par
Lorem ipsum dolor sit amet, vel ei ipsum animal. Sea intellegat interpretaris no. Vis id summo periculis, ut duo falli recteque. Id sea gubergren splendide repudiandae. Quo tota quaeque conclusionemque.}




% normal Arabic text:
\arabtext{%
\the\fontdimen2\font\quad
\the\fontdimen3\font\quad
\the\fontdimen4\font\par
وفي تشكيل الأمور ما, عُقر حادثة أصقاع عدم تم, دون واحدة فهرست بـ. أن بوابة ا الوزراء كلا. و إختار بمحاولة فقد, ذات أمّا مواقعها ان. إنطلاق المؤلّفة اليابان، تم.}

% tight Arabic text:
\arabtext{\tight{%
\the\fontdimen2\font\quad
\the\fontdimen3\font\quad
\the\fontdimen4\font\par
وفي تشكيل الأمور ما, عُقر حادثة أصقاع عدم تم, دون واحدة فهرست بـ. أن بوابة ا الوزراء كلا. و إختار بمحاولة فقد, ذات أمّا مواقعها ان. إنطلاق المؤلّفة اليابان، تم.}}

% should be normal Arabic text:
\arabtext{\nottight{%
\the\fontdimen2\font\quad
\the\fontdimen3\font\quad
\the\fontdimen4\font\par
وفي تشكيل الأمور ما, عُقر حادثة أصقاع عدم تم, دون واحدة فهرست بـ. أن بوابة ا الوزراء كلا. و إختار بمحاولة فقد, ذات أمّا مواقعها ان. إنطلاق المؤلّفة اليابان، تم.}}

\end{document}

For what it's worth, however, I think you might want to choose a better value than -2. WordSpace can change interword space, interword stretch, and interword shrink (respectively \fontdimens 2, 3, and 4). Another idea is to fudge the \spacefactor directly.

6
  • My first attempts were to create a single command combining do and undo as you suggest, but everything went entirely wrong so I split them (temporarily). Other than that, I just chose -2 to make the effect plainly visible. good answer. (The Arabic -- in case you wondered -- is nonsensical.) – ClintEastwood Jul 19 '15 at 16:19
  • @ClintEastwood -- Ah, the "Lorem ipsum" for Arabic, then? – jon Jul 19 '15 at 16:21
  • apparently so, yes. However, whereas Lorem ipsum at least looks like Latin, the Arabic text reveals itself more readily to be entirely off. – ClintEastwood Jul 19 '15 at 16:25
  • what I don't understand is why you added \the\fontdimen2\font\quad \the\fontdimen3\font\quad \the\fontdimen4\font\par again and again? – ClintEastwood Jul 20 '15 at 4:55
  • Oh, just to show what the settings were as one fiddles with WordSpace. Since it is not strictly additive, I thought it would be of interest, though I suppose I got carried away. (I found the difference between the description of WordSpace in the manual and the actual usage to be surprisingly divergent, however.) – jon Jul 21 '15 at 0:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.