2

I have an MWE below showing my problem (I got the general document outline from this answer:

\documentclass[twoside]{scrartcl}

\usepackage{fontspec}
\usepackage{polyglossia}
\usepackage{microtype}
\usepackage{lipsum}

\newfontfamily\cyrillicfontsf{CMU Sans Serif}[Script=Cyrillic]

% What I'm trying to replace
% \newfontfamily\cyrillicfont{CMU Serif}[Script=Cyrillic]

% What I'm trying to replace it with
\newcommand\mycommand[2]{\newfontfamily\csname#1font\endcsname{#2}[Script=Cyrillic]}
\mycommand{cyrillic}{CMU Serif}

\setmainlanguage{ukrainian}

\begin{document}
\author{А.В. Тор}
\title{Великий об'єм }
\maketitle
\section{Перший}
\lipsum[1-2]
\end{document}

So the problem here is that I feel as though what I'm trying to replace and what I'm trying to replace it by are equivalent. However, I am thrown the following error:

fontspec error: "font-not-found"
! 
! The font "c" cannot be found.
! 
! See the fontspec documentation for further information.
! 
! For immediate help type H <return>.
!............................................... 

So it seems to be taking just the first letter of the argument cyrillic, but that seems strange as I'm putting it in the \csname ... \endcsname environment. How should I go about fixing this?

I also tried \expandafter before the \newcommand, but that doesn't seem to work either.

  • I'm really dubious about the usefulness of such a command. – egreg Jul 4 '17 at 21:03
6
\newcommand\mycommand[2]{\newfontfamily\csname#1font\endcsname{#2}[Script=Cyrillic]}

\newfontfamily does not see a command sequence, but \csname as first argument. \expandafter helps by creating the command sequence before \newfontfamily parses its arguments:

\newcommand\mycommand[2]{\expandafter\newfontfamily\csname#1font\endcsname{#2}[Script=Cyrillic]}

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.