1

I have the trouble that I write the book in Azerbaijani, and I successfully use FontSpec. The only problem is following:

When I use\newcommand\ə{\char"04D9} as the command, it removes all space after itself like below, regardless of the position of the letter, however, I need to check if the next character is empty space.

enter image description here

trying to do this by \newcommand\ə{\char"04D9\@ifnextchar { }{ }} leads to improper result:

enter image description here

How to solve this? The code is below:

\documentclass[paper=7in:10in,DIV=calc,12pt]{scrbook}
\usepackage[inner=0.653in, outer=0.4in]{geometry}

\usepackage{pdfpages}

\newcommand\Ə{\char"04D8}
\newcommand\ə{\char"04D9\@ifnextchar{}{}}

\usepackage[none]{hyphenat}

\usepackage{fontspec}
\setmainfont[Ligatures={TeX,NoCommon}]{CMU Serif}
\setsansfont[Ligatures={TeX,NoCommon}]{CMU Sans Serif}

\begin{document}

\ə h\ə rfinin sonundakı boşluğu görmür.
11

2 Answers 2

4

If you give ə the category code 12(=other) instead of 11(=letter), then will not be a control-word-token but will be a control-symbol-token. TeX does not remove spaces after control-symbol-tokens unless the name of the control-symbol-token is formed by a character whose category code is 10(space).
Same can be done with Ə.

Disadvantage: If the category code of ə/Ə is 12, then at the time of tokenizing characters of lines of the .tex-input-file TeX won't consider ə/Ə a character that can be part of the multiletter-name of a control-word-token unless the control-word-token is constructed via \csname..\endcsname or comes from expanding a macro that was defined prior to switching the category code of ə/Ə to 12 or comes from \the-expansion of a token-register whose content was assigned prior to switching the category code of ə/Ə to 12.

% Compile with lualatex
\documentclass[paper=7in:10in,DIV=calc,12pt]{scrbook}
\usepackage[inner=0.653in, outer=0.4in]{geometry}

\usepackage{pdfpages}

\newcommand\Ə{\char"04D8 }%<-space terminates the number of the char and gets discarded
\newcommand\ə{\char"04D9 }%<-space terminates the number of the char and gets discarded
\catcode`\Ə=12
\catcode`\ə=12

\usepackage[none]{hyphenat}

\usepackage{fontspec}
\setmainfont[Ligatures={TeX,NoCommon}]{CMU Serif}
\setsansfont[Ligatures={TeX,NoCommon}]{CMU Sans Serif}

\begin{document}

\ə h\ə rfinin sonundakı boşluğu görmür.

\əh\ərfinin sonundakı boşluğu görmür.

\end{document}

enter image description here

Alternatively define / to be macros that are delimited by an explicit non-category-11(letter)-and-non-category-10(space)-character-token so that

  1. the non-category-11(letter)-character won't be considered part of the name of a control-word-token that begins with \Ə.../ \ə....
  2. a space trailing the delimiting non-category-10(space)-character-token won't be discarded as after tokenizing the delimiting non-category-10(space)-character-token TeX's reading-apparatus will be in state M(middle of line) instead of S(skipping blanks).

You can, e.g., use ! as delimiter:

% Compile with lualatex
\documentclass[paper=7in:10in,DIV=calc,12pt]{scrbook}
\usepackage[inner=0.653in, outer=0.4in]{geometry}

\usepackage{pdfpages}

\makeatletter
\@ifdefinable\Ə{\def\Ə!{\char"04D8 }}%<-space terminates the number of the char and gets discarded
\@ifdefinable\ə{\def\ə!{\char"04D9 }}%<-space terminates the number of the char and gets discarded
\makeatother

\usepackage[none]{hyphenat}

\usepackage{fontspec}
\setmainfont[Ligatures={TeX,NoCommon}]{CMU Serif}
\setsansfont[Ligatures={TeX,NoCommon}]{CMU Sans Serif}

\begin{document}

\ə! h\ə! rfinin sonundakı boşluğu görmür.

\ə!h\ə!rfinin sonundakı boşluğu görmür.

\end{document}

enter image description here


\@ifnextchar is not suitable for checking whether the next token in the token-stream is a space-token.

Reasons:

  1. The implementation of the \@ifnextchar-mechanism contains a lot of trickery for ensuring that TeX "looks" at the next non-space-token.
  2. \@ifnextchar is implemented to fail if its first argument is a space-token:
    \@ifnextchar is defined as follows:
    \long\def\@ifnextchar#1#2#3{%
      \let\reserved@d=#1\def\reserved@a{#2}\def\reserved@b{#3}\futurelet\@let@token\@ifnch
    }%
    
    In case #1 is a space-token, you have
    \let\reserved@d=⟨space-token⟩\def\reserved@a{#2}...
    According to the syntax-rules for \let a space-token behind = will be discarded, thus this is the same as
    \let\reserved@d=\def\reserved@a{#2}...
    , i.e., \reserved@d will have the meaning of the \def-primitive and \reserved@a and subsequent {#2} will be carried out instead of defining \reserved@a to yield #2.
    Subsequent erroneous behavior depending on the current definition/meaning of \reserved@a follows.
1

There are two similar characters in Unicode (as far as the shape is concerned)

  • U+0259 LATIN SMALL LETTER SCHWA ə
  • U+04D9 CYRILLIC SMALL LETTER SCHWA ә

(and their uppercase counterparts). Judging from your code, it seems you want to input the former and to get the latter.

I'm not sure why, because according to the Wikipedia page on the Azerbaijani alphabet, the Latin version is used, not the Cyrillic.

If you want to get the Cyrillic one, independently on how you input the character, you can use newunicodechar:

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

\setmainfont[Ligatures={TeX,NoCommon}]{CMU Serif}
\setsansfont[Ligatures={TeX,NoCommon}]{CMU Sans Serif}

\newunicodechar{Ə}{Ә} % U+018F -> U+04D8
\newunicodechar{ә}{ә} % U+0259 -> U+04D9

\begin{document}

ə hə rfinin sonundakı boşluğu görmür.

Ə hə rfinin

\end{document}

enter image description here

A different matter would be if you want ə (U+0259) to produce itself, but to produce the Cyrillic similar character. In that case, turn ə into category code 12.

\documentclass{article}
\usepackage{fontspec}

\setmainfont[Ligatures={TeX,NoCommon}]{CMU Serif}
\setsansfont[Ligatures={TeX,NoCommon}]{CMU Sans Serif}

\catcode`Ə=12
\newcommand{\Ə}{\symbol{"04D8}} % U+018F -> U+04D8
\catcode`ə=12
\newcommand{\ə}{\symbol{"04D9}} % U+0259 -> U+04D9

\begin{document}

ə hə rfinin sonundakı boşluğu görmür.

\ə h\ə rfinin sonundakı boşluğu görmür.

Ə hə rfinin

\Ə hə rfinin

\end{document}

enter image description here

Try copying and pasting from the produced PDF and you'll see that the expected character is used.

2
  • I don't know why, but in the font packages, it is almost impossible to find the Latin Ə in the font packages, but easy to find Cyrilic Ə, so that's why I try to use it. Otherwise, of course, all letters should be Latin ones. Dec 9, 2021 at 1:16
  • So this is what I wanted, now everything is OK. Dec 9, 2021 at 1:23

You must log in to answer this question.

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