1

I have somewhat a follow-up to this question. I figured that it would be better to have a regular em-dash (---) whose size and spacing rules adjust depending on current language. So when \language[ru] is set, it should give \unskip\thinspace\cyrdash\hskip.166em\ignorespaces, where \cyrdash defined as \scale[sx=0.85]{–}, for example.

What is the most correct way of implementing this in ConTeXt?

UPD1: What I'm basically looking for is some test command for finding which language is currently used.

3 Answers 3

4

You can use combination of a font switch the character spacing to change the appearance of the em-dash. In the first step you create a separate typeface with a compressed em-dash.

\definefontfeature[russian][extend=0.8]

\definefallbackfamily [russianfont] [rm] [DejaVu Serif] [range={0x2013,0x2014},force=yes,features=russian]
\definefontfamily     [russianfont] [rm] [DejaVu Serif]

\definefontfamily     [latinfont]   [rm] [DejaVu Serif]

\setupbodyfont[latinfont]

\starttext

em—dash

\blank \switchtobodyfont[russianfont]

em—dash

\stoptext 

enter image description here

The next step is to add spaces before and after the em-dash.

\definecharacterspacing [russianpunctuation]
\setupcharacterspacing  [russianpunctuation] ["2014] [left=.16667,right=.16667,alternative=1]

\starttext

em—dash

\blank \setcharacterspacing[russianpunctuation]

em—dash

em — dash

\stoptext  

enter image description here

To ensure that the em-dash is taken from the fallback font when you use --- in your document the translate module is needed.

\usemodule[translate]

\translateinput[---][—]

\enableinputtranslation

\starttext

em---dash

\stoptext 

enter image description here

The last step is to enable these settings only when you change the language, this can be done by putting the commands in a setups-environment and enabling it with \setuplanguage.

\usemodule[translate]

\translateinput[---][—]

\definefontfeature[russian][extend=0.8]

\definefallbackfamily [russianfont] [rm] [DejaVu Serif] [range={0x2013,0x2014},force=yes,features=russian]
\definefontfamily     [russianfont] [rm] [DejaVu Serif]

\definefontfamily     [latinfont]   [rm] [DejaVu Serif]

\setupbodyfont[latinfont]

\definecharacterspacing [russianpunctuation]
\setupcharacterspacing  [russianpunctuation] ["2014] [left=.16667,right=.16667,alternative=1]

\startsetups[russian]

    \enableinputtranslation
    \switchtobodyfont[russianfont]
    \setcharacterspacing[russianpunctuation]

\stopsetups

\setuplanguage[ru][setups=russian]

\starttext

em—dash

\blank \language[ru]

em—dash

\stoptext

enter image description here

5
  • great answer, and seems much more "correct", I'm tempted to revote) however it suffers from the same problem as the unedited one above: Russian text dash can be at an end of line. Could you modify it to make it that way?
    – The_Keeper
    Jun 5, 2016 at 14:40
  • @The_Keeper What is your expected behavior for the em-dash at a line break? Jun 5, 2016 at 15:01
  • so, the Russian em-dash either stays at the end of line ('word1 word2 --- | word3') or moves with part or whole of preceding word to the next line ('word1 | word2 --- word3')
    – The_Keeper
    Jun 5, 2016 at 15:15
  • 1
    @The_Keeper The \setupcharacterspacing I used in the example keeps the preceding and following words together. To have a possible line break also after the em-dash you can use the \definebreakpoint commands but it has a few limitations, a) user inserted spaces before and after the em-dash aren’t removed and b) the fallback font which was used to generate a narrower em-dash isn’t used anymore. Jun 5, 2016 at 18:37
  • Narrower font idea is great, I'd love to find a workaround to overcome these limitations.
    – The_Keeper
    Jun 5, 2016 at 18:50
2

One option is to have language specific hspace:

\define\cyrdash{\dontleavehmode\scale[sx=0.80]{---}}  

\setuplanguage
  [ru]
  [midsentence=\cyrdash,
   leftsentence=\cyrdash,
   rightsentence=\cyrdash]

\definehspace      [emdash] [\zeropoint]
\definehspace [ru] [emdash] [2cm] % Exaggerated, for visualization.

\definetextmodediscretionary <
  {\beginofsubsentence\prewordbreak\kern\hspaceamount\currentlanguage{emdash}}

\mainlanguage[ru]
\setupbodyfont[dejavu]

\starttext
Normal text|<|Russian
\stoptext
2
  • I'm sorry, but using different symbols is not what I'm looking for. Can I actually redefine the three-hyphen (---) em-dash for different language?
    – The_Keeper
    Jun 5, 2016 at 6:40
  • Well, you liked to that question, so I uses the method listed there.
    – Aditya
    Jun 5, 2016 at 13:43
2

This also removes the burden of typing different em-dashes for different situations. You just type --- or (unicode em-dash) and it will adjust depending of the position.

\usemodule[translate]
\translateinput[---][—]

\define\cyrdashsymbol{\dontleavehmode\scale[sx=0.80]{---}}  % cyrillic dash sign
\unexpanded\def\cyrdash{\ifincsname\string—\else
  \ifvmode\leavevmode\cyrdashsymbol\hskip.35em
  \else\unskip\thinspace\cyrdashsymbol\hskip.166667em 
\fi\fi\ignorespaces}

\catcode`\—=\active
\unexpanded\def—{\doifelse{\currentlanguage}{ru}{\cyrdash}{---}}

\mainlanguage[russian]
\setupbodyfont[dejavu]

\starttext\enableinputtranslation

--- Прямая речь --- \quotation{после \quote{тире} неразрывный пробел}.

— Прямая речь — \quotation{после \quote{тире} неразрывный пробел}.

\stoptext

Since active characters is not the ideal solution in ConTeXt, here's another solution that avoids active characters (which is not neccesarily correct, by the way).

\usemodule[translate]
\translateinput[---][\doifelse{\currentlanguage}{ru}{\cyrdash}{---}]
\translateinput[—][\doifelse{\currentlanguage}{ru}{\cyrdash}{---}]

\unexpanded\def\cyrdashsymbol{\dontleavehmode\scale[sx=0.80]{---}}
\unexpanded\def\cyrdash{\ifincsname\detokenize{—}\else
  \ifvmode\leavevmode\cyrdashsymbol\hskip.35em
  \else\unskip\thinspace\cyrdashsymbol\hskip.166667em 
\fi\fi\ignorespaces}

\mainlanguage[russian]
\setupbodyfont[dejavu]

\starttext\enableinputtranslation

--- Прямая речь --- \quotation{после \quote{тире} неразрывный пробел}.

— Прямая речь — \quotation{после \quote{тире} неразрывный пробел}.

\stoptext
12
  • yeah, some test for current language is exactly what I'm looking for. Thanks for advice on this kind of auto-adjustment anyway)
    – The_Keeper
    Jun 5, 2016 at 9:01
  • Well, you have \currentlanguage.
    – Manuel
    Jun 5, 2016 at 9:39
  • can you provide an example? while printed, currentlanguage reads 'ru', the following line \ifx\currentlanguage{ru} yes \else no \fi returns 'no'.
    – The_Keeper
    Jun 5, 2016 at 10:11
  • 1
    I already wrote it, this is the relevant part: \doifelse{\currentlanguage}{ru}{\cyrdash}{---}.
    – Manuel
    Jun 5, 2016 at 10:33
  • 1
    I've edited your answer (changed last \thinspace to \hskip.166em because dash doesn't have to go to the next line), and accepted it
    – The_Keeper
    Jun 5, 2016 at 10:58

You must log in to answer this question.

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