2

Assume I need to sandwich English words in chapter titles which are mainly in Burmese. I want those sandwiched English words in red color. However I want to have all the headers text only in gray keeping the same font in the original chapter titles. How can I achieve that? Here is my MWE:

\documentclass[twoside, openright]{book}
\XeTeXlinebreaklocale "my_MM"  %Myanmar line and character breaks
\XeTeXinterwordspaceshaping = 2

\usepackage{fontspec}
\usepackage[dvipsnames]{xcolor}
\usepackage{titlesec}

\newfontfamily{\ubuntumono}{Fira Mono}[Script=Latin]% replace Fira with Ubuntu
\DeclareTextFontCommand{\textubuntumono}{\ubuntumono}

\newcommand{\class}{\myCodePar{class}}
\newcommand{\turnLeft}{\myCodePar{turnLeft}}

\NewDocumentCommand{\myCodePar}{om}{%
  % #1 = optional color, #2 = text
  \textubuntumono{\IfValueT{#1}{\addfontfeatures{Color=#1}}#2}%
}

\definecolor{myParColor}{HTML}{4E4D4D}
\definecolor{myParColor1}{rgb}{1,0,0}

\titleformat{\chapter}[display]
    {\Huge}{\color{blue}\thechapter}{10pt}{\color{blue}}
    {\filcenter} 

\renewcommand{\chaptermark}[1]{%
    % header မှာ အခန်း ၁ ကို boldfont နဲ့ မစောင်းပဲပေါ်အောင် 
    \markboth{{\color{gray}\bfseries{\chaptername\ \thechapter~~~}}% 
        % chapter title ကို italic နဲ့ ပေါ်အောင် 
        {\color{gray}\bfseries{#1}}}{}}


\begin{document}

\chapter{Burmese Txt \myCodePar[red]{Some Eng Txt} Burmese Txt}
\newpage
sometext
\newpage
sometext

\end{document}

enter image description here

enter image description here

4
  • Can you please add a screenshot to your question?
    – MS-SPO
    Aug 11, 2022 at 9:16
  • 1
    @MS-SPO, sure. I've added screenshots.
    – Pyi Soe
    Aug 11, 2022 at 9:20
  • This is one way \chapter[Burmese Txt Some Eng Txt Burmese Txt]{Burmese Txt \myCodePar[red]{Some Eng Txt} Burmese Txt}. Put into [] what goes to the header. Aug 11, 2022 at 13:57
  • So you are using the optional [subtitel] for this purpose to "remove" colors, right? (@PyiSoe See e.g. here dickimaw-books.com/latex/novices/html/sectionunits.html , and follow the chapter-link)
    – MS-SPO
    Aug 11, 2022 at 14:35

1 Answer 1

1

You could make \myCodePar do nothing inside the header.

\NewDocumentCommand{\NotmyCodePar}{om}{#2}

\renewcommand{\chaptermark}[1]{%
    % header မှာ အခန်း ၁ ကို boldfont နဲ့ မစောင်းပဲပေါ်အောင် 
    \markboth{{\color{gray}\bfseries{\chaptername\ \thechapter~~~}}% 
        % chapter title ကို italic နဲ့ ပေါ်အောင် 
        {\color{gray}\bfseries{\let\myCodePar\NotmyCodePar#1}}}{}}

enter image description here

3
  • @Oostrum thanks for the help. I noticed your method change the font as well, not just the color. Is it possible to just change the color of the font in the header retaining the font type.
    – Pyi Soe
    Aug 13, 2022 at 2:52
  • You could copy the font from \myCodePar into \NotmyCodePar if you want to retain that. Aug 13, 2022 at 7:46
  • Thank! I just have tested and it produced the result I need.
    – Pyi Soe
    Aug 17, 2022 at 17:47

You must log in to answer this question.

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