2

I'm sorry for have been unprecise. So again. I want to have every text in the entire document in a diffrent colour, if it is written in a fontshape which does not exist in the user defined font. I'm using XeLaTeX and hope, that the following code can expain it better to you all.

\documentclass{scrreprt}
    \usepackage[ngerman]{babel}
    %\usepackage{xparse}
    \usepackage{xcolor,blindtext}
    \usepackage{xltxtra}
    \makeatletter
    \NewDocumentCommand{\fntInf}{}{\tiny \f@family, \f@series, \f@shape\normalsize}
     \makeatother
        \setmainfont[
              ItalicFeatures={Color=FF000099}% That doesn't work
        ]{Source Serif Pro}% This font comes without support for italic or small caps. Is there a way to mark all textes which are have been automatical replaced because of an  invalid font shape/series by fontspec?
        \setmonofont{Source Serif Pro}
        \setromanfont{Source Serif Pro}

    \begin{document}
    \begin{quote}
    Lalal asflas mesltne twt gheptwhpsfn\fntInf

    \textbf{ Aw hfafjat awl \fntInf\\ \\hfalfhal hawlfnals \itshape nawlhaw lfaitiowjpaöfka\fntInf} 
    \end{quote}
    \end{document}

[Old Question, please do ignore the following text.] Is it anyhow possible to colourize the text, if the bold version of the font underneath is used (automatically!!)?

\newfontfamily{\FMonoB}[%
                ItalicFont={Anonymous Pro Italic},
                BoldItalicFont={Ani}]
            {Source Code Pro}

I thought I could use \addfontfeature{Color=FF000099} anyhow, but I couldn't find a solution.

Here's an example:

\documentclass[twoside, paper=A4, 11pt]{scrreprt}
\usepackage[ngerman]{babel}
\usepackage{xparse}
\usepackage{xcolor,blindtext,multicol} % für farbigen Text
\usepackage{xltxtra}
%\usepackage{libertine}

\newfontfamily{\FMonoA}%[%
            %BoldItalicFont={Consolas}]% I want to have this always in a diffrent color.
            {Consolas} % or 'Source Code Pro'

\begin{document}
Lalal asflas mesltne twt nwtnwthigheptwhpsfn {\FMonoA\textbf{\itshape aw hfafjat}} awl hfalfhal hawlfnals nawlhaw lfaitiowjpaöfka 
\end{document}

"aw hfafjat" should be in another color. Whenever I use \FMonoA in a bold+italic combination the text shall be in a different color. Idea? \addfontfeature and color=. But how?

2
  • 3
    Please consider accepting answers to your earlier questions. One has 3 answers; another 2. And please include a complete Minimal Working Example when asking questions, which we can compile. This helps to clarify your question, makes it easier to help and more likely answers will help.
    – cfr
    Mar 26, 2017 at 3:46
  • I've taken the liberty of moving the bulk of your follow-up "answer" to body of the query. That way, hopefully, it will be visible more readily to readers.
    – Mico
    Mar 26, 2017 at 7:03

2 Answers 2

9

I would use the well-documented feature of fontspec called BoldFeatures. It allows you to provide many features regarding the bold font. It works perfectly with Xe/Lua LaTeX. I suggest you to look up for the package documentation

Here is a MWE

\documentclass{article}
\usepackage{fontspec}
\setmainfont[BoldFeatures={Color=0000ff}]{Linux Libertine O}
\begin{document}
test
\textbf{text}
\end{document}

enter image description here

A more detailed example:

\documentclass{article}
\usepackage{fontspec}
\usepackage{xcolor}

\newfontfamily{\FMonoA}{Source Code Pro}[
  Scale=MatchLowercase,
  ItalicFont=TeX Gyre Cursor Italic,
  ItalicFeatures={Scale=MatchLowercase},
  BoldItalicFont=Inconsolatazi4-Bold,
  BoldItalicFeatures={
    Color=blue,
    FakeSlant=0.25,
    Scale=MatchLowercase,
  },
]

\begin{document}

aa bb cc {\FMonoA\textbf{\textit{uuvvww}}}

aa bb cc {\FMonoA\textbf{uuvvww}}

aa bb cc {\FMonoA\textit{uuvvww}}

\end{document}

enter image description here

0
7

Note that this answer is NOT an answer to the current question, but to the ORIGINAL one.

No example, no code, no context. Here's a generic solution. Not specific to XeTeX. Compiles just the same with XeLaTeX or pdfLaTeX.

\documentclass{article}
\usepackage{xcolor}
\makeatletter
\DeclareRobustCommand\bfseries
{\not@math@alphabet\bfseries\mathbf
  \fontseries\bfdefault\selectfont\color{blue}}
\makeatother
\begin{document}
Here is some text.

\textbf{Here is some bold.}

Here is some more.

{\bfseries
  This is in bold.%
}

Here is the last.
\end{document}

bold blue

The advantage of this is that all bold text will be blue, but that bold mathematics will be untouched, and that the solution is engine-agnostic. That is, the same solution will work for pdfTeX as for XeTeX etc. as it does not depend on fontspec. In general, engine-agnostic solutions are more flexible and portable.

It does not, however, address the edited version of the question and I would not have suggested it has that question been extant at the time this was written.

5
  • Is it really necessary to redefine the bfseries command? Maybe this is the best option, but what makes it better than using fontspec specific commands?
    – Moriambar
    Mar 26, 2017 at 9:11
  • @ilFuria Given the original question, this seemed the obvious solution. If you want all bold text to be blue, say, then making it so that switching to bold switches to blue is the most straightforward way. Moreover, it is engine-agnostic, so it will work with pdfTeX or with XeTeX without fontspec. Hence, it is more flexible and portable. Of course, given the current question, it is not a good solution. But the current question is not the one I answered.
    – cfr
    Mar 26, 2017 at 15:58
  • 1
    I can understand this being down-voted as an answer to the current question, but down-voter please note that that was not the question I answered!
    – cfr
    Mar 26, 2017 at 16:00
  • I understand. I thought I might've missed something!
    – Moriambar
    Mar 26, 2017 at 16:02
  • @ilFuria Only the original version of the question, which turns out not to be the one the OP wants answering :-).
    – cfr
    Mar 26, 2017 at 16:06

You must log in to answer this question.

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