4

I am writing a UTF-8 (malayalam) document using Xelatex.

Below shown is my sample Latex code. If you see(screenshot) the Table Of Contents generated, you can see Noto Sans Malayalam which came because I had to type my UTF-8 text using my custom made \noto command \def\noto{\fontspec{Noto Sans Malayalam}} .

Do you know how to remove this unwanted text Noto Sans Malayalam in my pdf's Table of Contents ?

enter image description here

% xelatex test.tex 

\documentclass[a4paper,12pt]{article}

\usepackage{fontspec}
\usepackage{polyglossia}
\usepackage{tocloft}
\usepackage{hyperref}

\def\noto{\fontspec{Noto Sans Malayalam}}

\title{A title}

\begin{document}

\pagenumbering{arabic}
\renewcommand{\contentsname}{Contents \\ {\noto ഉളളടക്കം }}
\tableofcontents
\newpage

\section{Malayalam  \\ \noto{ മലയാളം } }

Malayalam \\ {\noto മലയാളം}
\newpage

\section{English  \\ \noto{ ഇംഗ്ലീഷ് }            }

English \\ {\noto ഇംഗ്ലീഷ്}

\end{document}
  • 3
    You may be interested in a little macro called \texorpdfstring{<tex>}{<pdf>}... – Werner Apr 23 '16 at 13:48
  • 1
    Use \newcommand\noto{\texorpdfstring{\fontspec{Noto Sans Malayalam}}{}} – Ulrike Fischer Apr 23 '16 at 13:48
  • Do you need the english and malayalam to be in different fonts? If not, why not just set the main font \setmainfont? – AJN Apr 23 '16 at 14:00
4

The .pdf file can't interpret the \noto command and the font specification correctly for the bookmarks.

Use \texorpdfstring{\fontspec{...}}{}

I've removed the 'wrong' \\ usages as well.

The Noto fonts can be downloaded from https://www.google.com/get/noto/

\documentclass[a4paper,12pt]{article}

\usepackage{fontspec}
\usepackage{polyglossia}
\usepackage{tocloft}
\usepackage{hyperref}

\DeclareRobustCommand{\noto}{\texorpdfstring{\fontspec{Noto Sans Malayalam}}{}}

\title{A title}

\begin{document}

\pagenumbering{arabic}
\renewcommand{\contentsname}{Contents \\ {\noto ഉളളടക്കം }}
\tableofcontents
\newpage

\section{Malayalam  \noto{ മലയാളം } }

Malayalam 

 {\noto മലയാളം}

\clearpage
\section{English   \noto{ ഇംഗ്ലീഷ് }            }

English 

{\noto ഇംഗ്ലീഷ്}

\end{document}

enter image description here

  • Is it wrong to use "\\ " ? Or you meant I used at wrong place ? – robomon Apr 23 '16 at 15:44
  • @robomon: leave an empty line rather in normal text if you want a linebreak. In the \section etc. headings, well, use \` rather then or \[1ex]`. – user31729 Apr 23 '16 at 15:45
2

You want to have neither \\ nor \noto in the bookmarks. The simplest solution is to use a command for the section titles:

\documentclass[a4paper,12pt]{article}

\usepackage{fontspec}
\usepackage{polyglossia}
\usepackage{tocloft}
\usepackage{hyperref}

\newfontfamily\noto{Malayalam MN} % I don't have Noto
\newcommand{\nototitle}[1]{%
  \texorpdfstring{\\{\noto #1}}{#1}%
}

\title{A title}

\begin{document}

\pagenumbering{arabic}
\renewcommand{\contentsname}{Contents \\[1ex] {\noto ഉളളടക്കം}}

\tableofcontents
\newpage

\section{Malayalam\nototitle{മലയാളം}}

Malayalam \\ {\noto മലയാളം}
\newpage

\section{English\nototitle{ഇംഗ്ലീഷ്}}

English \\ {\noto ഇംഗ്ലീഷ്}

\end{document}

Don't use \fontspec in the body of the document; using \newfontface in the preamble once and for all is much more efficient.

enter image description here

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.