I want a \doifmode
for text mode or a \doifnotmode
for math mode but math and text are not defined as system modes by ConTeXt.
Hungarian typography requires small space before certain characters, including colons. I want to adapt that. However I want to avoid that for non-text modes.
Unfortunately I can not write a conditional code based on text/math mode which is rather frustrating.
Below is my ConTeXt MkIV code. It gives M0H0S0
for all 4 test cases. I would expect M0H1S0
, M0H1S1
, M1H0..
, M1H0..
.
\mainlanguage[hu]
% adapted from magyar.ldf (LaTeX Babel)
\def\thinspaced#1{%
% Dat: `!' at the end of the word is OK, but at the beginning it makes the
% word unhyphenatable. Imp: maybe \nobreak\hskip\z@skip?
% Dat: this is math-mode safe, because \ifhmode is false in math mode
\doifmode{*hu}{
% THE COMMENTED CODE SHOULD WORK BELOW
%\ifmmode% \ifhmode and \ifmmode are never true
% \ifdim\lastskip>\dimexpr0pt\relax
% \unskip\penalty\@M\kern.1em% \thinspace is .16667em
% \else
% \kern.1em
% \fi
%\fi
% TEMPORARY MODE TEST CODE BELOW
\ifmmode\/M1\else\/M0\fi
\ifhmode\/H1\else\/H0\fi
\ifdim\lastskip>\dimexpr0pt\relax\/S1\else\/S0\fi
}%
\string#1
}
\catcode`\:=\active \edef:{\thinspaced:}
\starttext
Test1: Test1
Test2 :Test2
Mathtest1 \math{20:30} Mathtest 1
Mathtest2
\startformula
20:30
\stopformula
Mathtest2
\stoptext
Note that I just started to use ConTeXt, have no deep TeX coding knowledge, used LaTeX before but that is not good enough for my typographic needs.
Thanks in advance!
EDIT: Henri's answer pointed out that \ifhmode
and \ifmmode
works as intended; the problem was with \edef
above.
:
,;
,!
and?
) add\setcharacterspacing [frenchpunctuation]
to your document.\setcharacterspacing
source code.frenchpunctation
space, defined my own punctation with only0.1em
spaces and now there are no more extra spaces before the marks in the resulting PDF. Everything works as intended. Thanks guys!