[XeTeX] Redefining \em and \emph

Gareth Hughes garzohugo at gmail.com
Tue Sep 28 01:50:28 CEST 2010


Will Robertson wrote:
> On 2010-09-25 09:33:20 +0930, Gareth Hughes <garzohugo at gmail.com> said:
> 
>> Will Robertson wrote:
>>> It doesn't seem to. In that case I'd write something like
>>>
>>> \let\oldemph\emph
>>> \renewcommand\emph{%
>>> \if at RTL \expandafter\aemph \else \expandafter\oldelse \fi
>>> }
>>
>> I still can't figure out how to do this for \eminnershape as defined in
>> fixltx2e. Any suggestions how to do that?
> 
> Do you mean so that you can write
> 
>    \aemph{ ... \aemph{ ...} ... }
> 
> and have the inner \aemph not put the overline on top? In this case, you
> can write (and this might be a reasonable addition to polyglossia)
> 
> \documentclass{article}
> \makeatletter
> \def\aemph#1{%
>  \begingroup
>    \let\aemph\inneraemph
>    $\overline{\hbox{#1}}$%
>  \endgroup
> }
> \def\inneraemph#1{%
>  \egroup% close \hbox
>  \egroup% close \overline
>  $% close math
>  {\eminnershape #1}% inner emphasis!
>  $% "reopen" math
>  \expandafter\overline\bgroup % "reopen" \overline
>  \hbox\bgroup % "reopen" \hbox
> }
> \makeatother
> \begin{document}
> hello there \aemph{foo \aemph{oof rab} bar} baz black
> \end{document}
> 
> Modulo checks for bidi and using \hboxR instead of \hbox and a "correct"
> definition for \eminnershape in this context, and so on. But this has
> nothing to do with the idea of \eminnershape: if you want to tie the two
> together, fontspec actually overrides fixltx2e's emph/eminnershape code:
> 
> \ExplSynaxOn
> \DeclareRobustCommand \em {
>  \@nomath\em
>  \tl_if_eq:xxTF \f at shape \itdefault \eminnershape
>  {
>    \tl_if_eq:xxTF \f at shape \sldefault \eminnershape \emshape
>  }
> }
> \DeclareTextFontCommand{\emph}{\em}
> \cs_set_eq:NN \emshape \itshape
> \cs_set_eq:NN \eminnershape \upshape
> \ExplSyntaxOff
> 
> Not sure if that helps directly...
> 
> Will

That is really interesting. My understanding of plain TeX is getting
better, but still rudimentary. The Expl3 stuff is beyond me at the moment.

I'm trying to write a package for writing Syriac under XeLaTeX, and part
of it is to allow the end user some simple commands to redefine emphasis
and inner emphasis for Syriac text. These might be changing text colour
(common in manuscripts), putting dots around text, overlining (\aemph),
changing the font style (using a Syriac style called Estrangelo) etc. I
think I'm trying to do too much, but I think it's possible. My muddled
and messy code is shown below. Any help greatly appreciated.

Thanks,

Gareth.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Emphasis styles}
%    \begin{macro}{\emphcolour}
%    \begin{macro}{\emphstyle}
% Define commands for changing emphasis.
%    \begin{macrocode}
\newcommand\emphcolour{\crimson}
\newcommand\xsy at emphestr{\ifdef{\estrfont}{\renewcommand\emshape{\estrfont}}%
	{\renewcommand\emshape{\syriacfont}}}
\newcommand\xsy at emphaemph{%
	\let\oldemph\emph
		\renewcommand\emph{%
		\if at RTL \expandafter\aemph \else \expandafter\oldemph \fi}}
\newcommand\xsy at emphred{\let\oldemph\emph
	\renewcommand\emph{\if at RTL \expandafter\emphcolour %
	\else \expandafter\oldemph \fi}}
\newlength{\xsy at dashwidth}\setlength{\dashdash}{.075em}\setlength{\fboxsep}{.15em}
\newcommand\xsy at dashbox[1]{\settowidth{\xsy at dashwidth}{#1}%
	\addtolength{\xsy at dashwidth}{.15em}\dashbox[\xsy at dashwidth][c]{#1}}
\newcommand\xsy at emphdash{\let\oldemph\emph
	\renewcommand\emph{\if at RTL \expandafter\xsy at dashbox %
	\else \expandafter\oldemph \fi}}
\newcommand\emphstyle[1]{%
	\ifstrequal{#1}{italic}{\renewcommand\emshape{\itshape}}{}%
	\ifstrequal{#1}{overline}{\xsy at emphaemph}{}%
	\ifstrequal{#1}{red}{\xsy at emphred}{}%
	\ifstrequal{#1}{estr}{\xsy at emphestr}{}%
	\ifstrequal{#1}{estrangelo}{\xsy at emphestr}{}%
	\ifstrequal{#1}{estrangela}{\xsy at emphestr}{}%
	\ifstrequal{#1}{slanted}{%
		\renewcommand\emshape{\addfontfeature{AutoFakeSlant=-0.3}\slshape}}{}%
	\ifstrequal{#1}{outline}{\renewcommand\emshape{\outlshape}}{}%
	\ifstrequal{#1}{dotted}{\xsy at emphdash}{}}
%    \end{macrocode}
%    \end{macro}\end{macro}
%    \begin{macro}{\inneremphcolour}
%    \begin{macro}{\inneremphstyle}
% Define commands for changing inner emphasis.
%    \begin{macrocode}
\newcommand\inneremphcolour{\gold}
\newcommand\xsy at inneremphestr{\ifdef{\estrfont}%
	{\renewcommand\eminnershape{\estrfont}}%
	{\renewcommand\eminnershape{\syriacfont}}}
\newcommand\xsy at inneremphaemph{%
	\let\oldeminnershape\eminnershape
		\renewcommand\eminnershape{%
		\if at RTL \expandafter\aemph \else \oldeminnershape \fi}}
\newcommand\xsy at inneremphred{\let\oldeminnershape\eminnershape
	\renewcommand\eminnershape{\if at RTL \inneremphcolour %
	\else \oldeminnershape \fi}}
\newcommand\xsy at inneremphdash{\let\oldemph\emph
	\renewcommand\emph{\if at RTL \expandafter\xsy at dashbox %
	\else \expandafter\oldemph \fi}}
\newcommand\inneremphstyle[1]{%
	\ifstrequal{#1}{italic}{\renewcommand\eminnershape{\itshape}}{}%
	\ifstrequal{#1}{overline}{\xsy at inneremphaemph}{}%
	\ifstrequal{#1}{red}{\xsy at inneremphred}{}%
	\ifstrequal{#1}{estr}{\xsy at inneremphestr}{}%
	\ifstrequal{#1}{estrangelo}{\xsy at inneremphestr}{}%
	\ifstrequal{#1}{estrangela}{\xsy at inneremphestr}{}%
	\ifstrequal{#1}{slanted}{%
	\renewcommand\eminnershape{\addfontfeature{AutoFakeSlant=-0.3}\slshape}}{}%
	\ifstrequal{#1}{outline}{\renewcommand\eminnershape{\outlshape}}{}%
	\ifstrequal{#1}{dotted}{\xsy at inneremphdash}{}}
%    \end{macrocode}
%    \end{macro}\end{macro}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


More information about the XeTeX mailing list