Multi-language LaTeX document with dozens of languages - latex

I'm a Technical Writer trying to output a Python-Sphinx website into a .pdf via LaTeX. The manual has a safety regulations and environmental compliance section with about 40+ languages in it. These languages all appear as-is in the base file - and .rst files have the same unicode support as .txt, so if Bulgarian renders appropriately in Cyrillic in the base file I'm assuming it's encoded correctly.
I already know to use either LuaLaTeX or XeLaTeX to render unicode properly, and I've already found that TeX files compiled from Sphinx/.rst render better under LuaLaTeX. Even so, under LuaLaTeX, the Greek and Cyrillic don't render at all (nor do accented letters, but for some reason Germanic eth/ð does render).
Everything I've seen on multi-language support involves one of several packages that require you to bracket each section with something like \begin{Russian}, but for all 40+ languages. With the base file being in a different format and the .tex file being generated automatically, every time I update the manual it would save over all the work I've done.
The best solution for me would be to put all the multi-language support in the header, and just say "hey dumb dumb... just render the unicode text as-is". As it is, the auto-generated frontspiece and ToC is unsatisfactory, so I'm keeping the header saved in a separate document and I'm pasting the better header in. Front-loading multi-language support by defining everything in the header is definitely the most ideal solution.
Any help would be good.
The following is the header provided by Python-Sphinx, with minor adjustments:
%% Generated by Sphinx.
\def\sphinxdocclass{report}
\documentclass[letterpaper,10pt,english]{sphinxmanual}
\ifdefined\pdfpxdimen
\let\sphinxpxdimen\pdfpxdimen\else\newdimen\sphinxpxdimen
\fi \sphinxpxdimen=.75bp\relax
\ifdefined\pdfimageresolution
\pdfimageresolution= \numexpr \dimexpr1in\relax/\sphinxpxdimen\relax
\fi
%% let collapsible pdf bookmarks panel have high depth per default
\PassOptionsToPackage{bookmarksdepth=5}{hyperref}
\PassOptionsToPackage{warn}{textcomp}
\usepackage[utf8]{inputenc}
\ifdefined\DeclareUnicodeCharacter
% support both utf8 and utf8x syntaxes
\ifdefined\DeclareUnicodeCharacterAsOptional
\def\sphinxDUC#1{\DeclareUnicodeCharacter{"#1}}
\else
\let\sphinxDUC\DeclareUnicodeCharacter
\fi
\sphinxDUC{00A0}{\nobreakspace}
\sphinxDUC{2500}{\sphinxunichar{2500}}
\sphinxDUC{2502}{\sphinxunichar{2502}}
\sphinxDUC{2514}{\sphinxunichar{2514}}
\sphinxDUC{251C}{\sphinxunichar{251C}}
\sphinxDUC{2572}{\textbackslash}
\fi
\usepackage{cmap}
\usepackage[T1]{fontenc}
\usepackage{amsmath,amssymb,amstext}
\usepackage{babel}
\usepackage{tgtermes}
\usepackage{tgheros}
\renewcommand{\ttdefault}{txtt}
\usepackage[Bjarne]{fncychap}
\usepackage{sphinx}
\fvset{fontsize=auto}
\usepackage{geometry}
% Include hyperref last.
\usepackage{hyperref}
% Fix anchor placement for figures with captions.
\usepackage{hypcap}% it must be loaded after hyperref.
% Set up styles of URL: it should be placed after hyperref.
\urlstyle{same}
\usepackage{sphinxmessages}
\title{...}
\date{\today}
\release{...}
\author{...}
\makeindex
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
The document is almost entirely in English except for one dang section near but not at the end:
- Това е българско
- Αυτό είναι ελληνικό
- Tohle je česky
- Bu türkçe
- Þetta er íslenskt
\end{document}

Caveat: This won't give correct hyphenation and other special language settings (e.g. French spacing for punctuation marks), but it will show the text. If you want these other features as well, you will have to deal with babel or polyglossia.
The unicode capabilities of xe- and lualatex only fully unfold if you also use a font which does have a good coverage of symbols.
For example with the Noto Serif font:
% !TeX TS-program = lualatex
%% Generated by Sphinx.
\def\sphinxdocclass{report}
\documentclass[letterpaper,10pt,english]{sphinxmanual}
\ifdefined\pdfpxdimen
\let\sphinxpxdimen\pdfpxdimen\else\newdimen\sphinxpxdimen
\fi \sphinxpxdimen=.75bp\relax
\ifdefined\pdfimageresolution
\pdfimageresolution= \numexpr \dimexpr1in\relax/\sphinxpxdimen\relax
\fi
%% let collapsible pdf bookmarks panel have high depth per default
\PassOptionsToPackage{bookmarksdepth=5}{hyperref}
\PassOptionsToPackage{warn}{textcomp}
\usepackage[utf8]{inputenc}
\ifdefined\DeclareUnicodeCharacter
% support both utf8 and utf8x syntaxes
\ifdefined\DeclareUnicodeCharacterAsOptional
\def\sphinxDUC#1{\DeclareUnicodeCharacter{"#1}}
\else
\let\sphinxDUC\DeclareUnicodeCharacter
\fi
\sphinxDUC{00A0}{\nobreakspace}
\sphinxDUC{2500}{\sphinxunichar{2500}}
\sphinxDUC{2502}{\sphinxunichar{2502}}
\sphinxDUC{2514}{\sphinxunichar{2514}}
\sphinxDUC{251C}{\sphinxunichar{251C}}
\sphinxDUC{2572}{\textbackslash}
\fi
\usepackage{cmap}
\usepackage[T1]{fontenc}
\usepackage{amsmath,amssymb,amstext}
\usepackage{babel}
\usepackage{tgtermes}
\usepackage{tgheros}
\renewcommand{\ttdefault}{txtt}
\usepackage[Bjarne]{fncychap}
\usepackage{sphinx}
\fvset{fontsize=auto}
\usepackage{geometry}
% Include hyperref last.
\usepackage{hyperref}
% Fix anchor placement for figures with captions.
\usepackage{hypcap}% it must be loaded after hyperref.
% Set up styles of URL: it should be placed after hyperref.
\urlstyle{same}
\usepackage{sphinxmessages}
\title{...}
\date{\today}
\release{...}
\author{...}
\makeindex
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{fontspec}
\setmainfont{Noto Serif}
\begin{document}
The document is almost entirely in English except for one dang section near but not at the end:
- Това е българско
- Αυτό είναι ελληνικό
- Tohle je česky
- Bu türkçe
- Þetta er íslenskt
\end{document}
(to see which fonts on your computer support the characters you want to use, you can use the command line tool albatross, see e.g. https://stackoverflow.com/a/69721465/2777074)

Related

Missing = inserted for \ifnum

I am using iopart template, and I do not know why get this error :
Missing = inserted for \ifnum. \begin
Missing number, treated as zero. \begin
I really appreciate any help
\documentclass[10pt]{iopart}
%\newcommand{\gguide}{{\it Preparing graphics for IOP Publishing journals}}
%Uncomment next line if AMS fonts required
%\usepackage{iopams}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{nicefrac}
\expandafter\let\csname equation*\endcsname\relax
\expandafter\let\csname endequation*\endcsname\relax
\usepackage{amsmath,mathtools}
\DeclareMathOperator{\cotinv}{cot\,inverse}
\usepackage{amssymb}
\let\amscases\cases
\makeatletter
\def\cases{\#ifnextchar\bgroup\plaincases\amscases}
\def\plaincases#1{\begin{cases*}#1\end{cases*}}
\makeatother
\usepackage{multirow}
\usepackage{subfloat}
\usepackage{subfig}
\usepackage{gensymb}
%\newcommand{\acot}{\cot^{-1}}
\begin{document}
\title[]{}
\author{}
\author{}
\address{Department of}
\vspace{10pt}
\begin{indented}
\item[]November 2022
\end{indented}
\begin{abstract}
lll
\end{abstract}
%
% Uncomment for keywords
\vspace{2pc}
\noindent{\it Keywords}: electronics
%
% Uncomment for Submitted to journal title message
%\submitto{\JPA}
%
% Uncomment if a separate title page is required
\maketitle
%
% For two-column output uncomment the next line and choose [10pt] rather than [12pt] in the \documentclass declaration
\ioptwocol
%
\section{Introduction}\label{sec:introduction}
\end{document}```
I tried to recreate this instance. It first asked for the missing iopart.cls documentclass. I could get that from a GitHub repository belonging to Tianjin University named "etgroup". You can simply find it by searching "iop latex template" in Github. After the second compilation, it asked for a class dependency named iopart10.clo(it's available in the same repository).
Finally, after the third compilation, I could get a PDF output(Please see the figure attached).
Solution: If you are using a local LaTeX IDE/Studio, I recommend updating the packages you are using. Sometimes there are conflicts between some packages but they usually resolve quickly by releasing an update and you might see that there was nothing wrong with your commands.
Alternatively, you may try using an online LaTeX editor. They always have the last version of the most common packages and are equipped with multiple LaTeX render engine types.

Deleting redundant `\author` and `\affiliation` fields in R papaja document

I'm creating an R Markdown document using the 'papaja' package and the 'apa7' LaTeX template. When used together, the latter package and template currently produce a conflict due to duplicated \author and \affiliation fields in the tex file. Earlier, a method was found to resolve this conflict that worked by adding the following LaTeX commands to the preamble (through header-includes in the YAML header):
- \renewcommand\author[1]{}
- \renewcommand\affiliation[1]{}
However, this method is not currently working (I couldn't find out why). I've tried several modifications of the above code, such as \renewcommand\author{\phantom{}}{}, but to no avail.
The error can be reproduced with the following steps:
In RStudio, install the development version of the papaja package:
# Install devtools package if necessary
if(!"devtools" %in% rownames(installed.packages())) install.packages("devtools")
# Install the stable development verions from GitHub
devtools::install_github("crsh/papaja")
Click on the + button at the top left and create an R Markdown document.
Delete all the content in the new file and replace it with the following:
---
title : "Long title"
shorttitle : "Short title"
documentclass : apa7
classoption : man
output : papaja::apa6_pdf
header-includes:
- \authorsnames[1, 2, 2]{first author, second author, third author}
- \authorsaffiliations{{first affiliation}, {second affiliation}}
---
text text text text text text text text text.
Knit the document.
Notice the following error in the console:
! LaTeX Error: Command \c#NumberOfAuthors already defined.
Or name \end... illegal, see p.192 of the manual.
Error: LaTeX failed to compile Untitled.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See Untitled.log for more info.
Execution halted
Open the .tex file that has been produced, delete the two lines containing \author{\phantom{0}} and \affiliation{\phantom{0}}, and hit the Compile PDF button. Notice that the document is now knitted well.
For a single individual, the above workaround using the tex file might not be too problematic. However, it proves problematic for the reproducibility of the manuscript by other people.
I would be sincerely grateful if someone could suggest a solution based on some LaTex code entered in the header-includes preamble.
Thank you very much!
.tex file
% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[
english,
man]{apa7}
\title{Long title}
\author{\phantom{0}}
\date{}
\usepackage{amsmath,amssymb}
\usepackage{lmodern}
\usepackage{iftex}
\ifPDFTeX
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
\usepackage{unicode-math}
\defaultfontfeatures{Scale=MatchLowercase}
\defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
\usepackage[]{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\#ifundefined{KOMAClassName}{% if non-KOMA class
\IfFileExists{parskip.sty}{%
\usepackage{parskip}
}{% else
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
\KOMAoptions{parskip=half}}
\makeatother
\usepackage{xcolor}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\hypersetup{
pdftitle={Long title},
pdflang={en-EN},
hidelinks,
pdfcreator={LaTeX via pandoc}}
\urlstyle{same} % disable monospaced font for URLs
\usepackage{graphicx}
\makeatletter
\def\maxwidth{\ifdim\Gin#nat#width>\linewidth\linewidth\else\Gin#nat#width\fi}
\def\maxheight{\ifdim\Gin#nat#height>\textheight\textheight\else\Gin#nat#height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
% Set default figure placement to htbp
\makeatletter
\def\fps#figure{htbp}
\makeatother
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{-\maxdimen} % remove section numbering
% Make \paragraph and \subparagraph free-standing
\ifx\paragraph\undefined\else
\let\oldparagraph\paragraph
\renewcommand{\paragraph}[1]{\oldparagraph{#1}\mbox{}}
\fi
\ifx\subparagraph\undefined\else
\let\oldsubparagraph\subparagraph
\renewcommand{\subparagraph}[1]{\oldsubparagraph{#1}\mbox{}}
\fi
% Manuscript styling
\usepackage{upgreek}
\captionsetup{font=singlespacing,justification=justified}
% Table formatting
\usepackage{longtable}
\usepackage{lscape}
% \usepackage[counterclockwise]{rotating} % Landscape page setup for large tables
\usepackage{multirow} % Table styling
\usepackage{tabularx} % Control Column width
\usepackage[flushleft]{threeparttable} % Allows for three part tables with a specified notes section
\usepackage{threeparttablex} % Lets threeparttable work with longtable
% Create new environments so endfloat can handle them
% \newenvironment{ltable}
% {\begin{landscape}\begin{center}\begin{threeparttable}}
% {\end{threeparttable}\end{center}\end{landscape}}
\newenvironment{lltable}{\begin{landscape}\begin{center}\begin{ThreePartTable}}{\end{ThreePartTable}\end{center}\end{landscape}}
% Enables adjusting longtable caption width to table width
% Solution found at http://golatex.de/longtable-mit-caption-so-breit-wie-die-tabelle-t15767.html
\makeatletter
\newcommand\LastLTentrywidth{1em}
\newlength\longtablewidth
\setlength{\longtablewidth}{1in}
\newcommand{\getlongtablewidth}{\begingroup \ifcsname LT#\roman{LT#tables}\endcsname \global\longtablewidth=0pt \renewcommand{\LT#entry}[2]{\global\advance\longtablewidth by ##2\relax\gdef\LastLTentrywidth{##2}}\#nameuse{LT#\roman{LT#tables}} \fi \endgroup}
% \setlength{\parindent}{0.5in}
% \setlength{\parskip}{0pt plus 0pt minus 0pt}
% Overwrite redefinition of paragraph and subparagraph by the default LaTeX template
% See https://github.com/crsh/papaja/issues/292
\makeatletter
\renewcommand{\paragraph}{\#startsection{paragraph}{4}{\parindent}%
{0\baselineskip \#plus 0.2ex \#minus 0.2ex}%
{-1em}%
{\normalfont\normalsize\bfseries\itshape\typesectitle}}
\renewcommand{\subparagraph}[1]{\#startsection{subparagraph}{5}{1em}%
{0\baselineskip \#plus 0.2ex \#minus 0.2ex}%
{-\z#\relax}%
{\normalfont\normalsize\itshape\hspace{\parindent}{#1}\textit{\addperi}}{\relax}}
\makeatother
% \usepackage{etoolbox}
\makeatletter
\patchcmd{\HyOrg#maketitle}
{\section{\normalfont\normalsize\abstractname}}
{\section*{\normalfont\normalsize\abstractname}}
{}{\typeout{Failed to patch abstract.}}
\patchcmd{\HyOrg#maketitle}
{\section{\protect\normalfont{\#title}}}
{\section*{\protect\normalfont{\#title}}}
{}{\typeout{Failed to patch title.}}
\makeatother
\usepackage{xpatch}
\makeatletter
\xapptocmd\appendix
{\xapptocmd\section
{\addcontentsline{toc}{section}{\appendixname\ifoneappendix\else~\theappendix\fi\\: #1}}
{}{\InnerPatchFailed}%
}
{}{\PatchFailed}
\usepackage{csquotes}
\authorsnames[1, 2, 2]{first author, second author, third author}
\authorsaffiliations{{first affiliation}, {second affiliation}}
\ifXeTeX
% Load polyglossia as late as possible: uses bidi with RTL langages (e.g. Hebrew, Arabic)
\usepackage{polyglossia}
\setmainlanguage[]{english}
\else
\usepackage[main=english]{babel}
% get rid of language-specific shorthands (see #6817):
\let\LanguageShortHands\languageshorthands
\def\languageshorthands#1{}
\fi
\ifLuaTeX
\usepackage{selnolig} % disable illegal ligatures
\fi
\shorttitle{Short title}
\affiliation{\phantom{0}}
\begin{document}
\maketitle
text text text text text text text text text.
\end{document}
Quick hack:
---
title : "Long title"
shorttitle : "Short title"
documentclass : apa7
classoption : man
output : papaja::apa6_pdf
header-includes:
- \xpatchcmd{\authorsnames}{\newcounter{NumberOfAuthors}}{\setcounter{NumberOfAuthors}{0}}{}{}
- \xpatchcmd{\authorsnames}{\newcounter{NumberOfSuperscripts}}{\setcounter{NumberOfSuperscripts}{0}}{}{}
- \authorsnames[1, 2, 2]{first author, second author, third author}
- \authorsaffiliations{{first affiliation}, {second affiliation}}
- \renewcommand{\affiliation}[1]{}
---
text text text text text text text text text.
I found a book on the Papaja package. That link will bring you to the YAML section. I think this is what you were looking for.
First, there doesn't appear to be an association for APA 7, unless you have the development version of Papaja. That being said, there is a ticket on this in their main github.
If you set the output to apa6_docx, this "and &" error won't be there. (And even if it were, you could have deleted it.) You can save it as a PDF from there. I'm not sure if this is an option for you, but I thought I would mention it.
This is what it states about subsequent authors (and much more).
---
title : "Long title"
shorttitle : "Short title"
author:
- name : "First Author"
affiliation : "1"
- name : "Second Author"
affiliation : "1"
- name : "Third Author"
affiliation : "2"
affiliation:
- id : "1"
institution : "The University"
- id : "2"
institution : "The Other University"
documentclass : apa7
classoption : man
output : papaja::apa6_docx
---
text text text text text text text text text.

"Error Producing PDF" when markdown contains a horizontal rule: --- or ***

When my Markdown file contains a horizontal rule --- or *** I receive an error regarding \Linethickness -> \Protect
I understand there have been issues with MiKTeX recently, however I am unsure whether they apply here.
I have been experiencing this issue since yesterday morning, when I was playing around trying to get the Lato font package to work with a set of Markdown files I need to convert to PDF. It had been working fine (asides from the font issue).
This could have happened when I updated MiKTeX, although at the time I hadn't realised that could be the case, as I was also playing with the templates, YAML, PS Script etc.
Since then I've been reading about the MiKTeX issue and I've tried further updates, updating package database, building formats, refreshing file name database and uninstalling and reinstalling. I have read the background in the comments section on GitHub but the suggestions there do not seem to have solved it for me, whereas they have for others.
This makes me question whether this is related, but I am relatively new to Tex, Markdown etc.
The original file was longer and more complex, but this Markdown
# Sample File
Test Test Test
---
Produces the same error
Error producing PDF.
! Missing number, treated as zero.
<to be read again>
\protect
\linethickness ->\protect
\linethickness
\setlength #1#2->#1 #2
\relax
\#rule ...#tempdimb {#2}\setlength \#tempdimc {#3}
\advance \#tempdimc \#temp...
l.362 ...nter}\rule{0.5\linewidth}{\linethickness}
Removing the --- allows the pdf to generate in both the above example and my more complex markdown file, even with templates.
I am unsure if linethickness is within the graphics package, when I look at package information I can't see anything that obviously indicates it is.
I would simply remove the offending lines but they are used throughout the remainder of the markdown files and I would prefer to find a fix, with your help, if possible!
Please could you let me know if I'm barking up the wrong tree with this recent MiKTeX issue or not, and if not, where I might be going wrong.
Many Thanks in advance.
Update:
I ran this command
pandoc -s sample.md -o sample.tex
to produce this tex:
% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[
]{article}
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
\usepackage{unicode-math}
\defaultfontfeatures{Scale=MatchLowercase}
\defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
\usepackage[]{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\#ifundefined{KOMAClassName}{% if non-KOMA class
\IfFileExists{parskip.sty}{%
\usepackage{parskip}
}{% else
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
\KOMAoptions{parskip=half}}
\makeatother
\usepackage{xcolor}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\hypersetup{
hidelinks,
pdfcreator={LaTeX via pandoc}}
\urlstyle{same} % disable monospaced font for URLs
\usepackage[margin=1cm]{geometry}
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{-\maxdimen} % remove section numbering
\date{}
\begin{document}
\setcounter{errorcontextlines}{40}
\hypertarget{sample-file}{%
\section{Sample File}\label{sample-file}}
Test Test Test
\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
\end{document}
meanwhile, I tried this (as root in a latest RStudio Debian install):
~# sed 's,\\linethickness,0.5000000000pt,g' < pandoc/pandoc > /usr/lib/rstudio-server/bin/pandoc/pandoc
where the 1st pandoc/pandoc is a copy of the original from package. That keeps the same string length and valid number so that the binary won't break. That writes the hrule as:
\begin{center}\rule{0.5\linewidth}{0.5000000000pt}\end{center}
and MiKTeX seems fine with it (at least TeXworks compiles the pdf).
HTH
bye

Customize headers and footers in Latex using Sphinx

We are exploring the features of Sphinx in order to rebuild our legacy manuals. We already ported most of the former manual to Sphinx. Now I'm exploring the possibilities to adapt our company styles.
Especially, we would like to change the appearance of the headers and footers in the PDF manual. Including a company logo and changing the appearance of even and odd pages.
Hence, I included the following preamble in my conf.py with a custom pagestyle using the package fancyhdr.
latex_elements = {
'preamble' : '''\
\\pagestyle{fancy}
\\fancyhf{}
\\fancyhead[LE,RO]{My Header}'''
}
Unfortunately, the headers only changes before begin{document}, afterwards the Sphinx Style File sphinx.sty overwrites somehow my settings.
The following snippet from sphinx.sty might cause the issue:
% Redefine the 'normal' header/footer style when using "fancyhdr" package:
\spx#ifundefined{fancyhf}{}{
% Use \pagestyle{normal} as the primary pagestyle for text.
\fancypagestyle{normal}{
\fancyhf{}
\fancyfoot[LE,RO]{{\py#HeaderFamily\thepage}}
\fancyfoot[LO]{{\py#HeaderFamily\nouppercase{\rightmark}}}
\fancyfoot[RE]{{\py#HeaderFamily\nouppercase{\leftmark}}}
\fancyhead[LE,RO]{{\py#HeaderFamily \#title, \py#release}}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}
% define chaptermark with \#chappos when \#chappos is available for Japanese
\spx#ifundefined{#chappos}{}
{\def\chaptermark##1{\markboth{\#chapapp\space\thechapter\space\#chappos\space ##1}{}}}
}
% Update the plain style so we get the page number & footer line,
% but not a chapter or section title. This is to keep the first
% page of a chapter and the blank page between chapters `clean.'
\fancypagestyle{plain}{
\fancyhf{}
\fancyfoot[LE,RO]{{\py#HeaderFamily\thepage}}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0.4pt}
}
}
What might be a possible workaround?
The table of contents code (in sphinxmanual.cls) ends up with
\ifdefined\fancyhf\pagestyle{normal}\fi
The comment in sphinx.sty says:
% Use \pagestyle{normal} as the primary pagestyle for text.
Thus the simplest should be for your conf.py setting to overwrite the \fancypagestyle{normal}, just re-issue it to your liking.
You will need to wrap the whole latex in \makeatletter...\makeatother if you use \py#HeaderFamily. And use Python raw strings to avoid having to double all backslashes.
in details, here I copy the original definition to conf.py so that it can be customized from there
latex_elements = {
'preamble': """
\makeatletter
\fancypagestyle{normal}{
\fancyhf{}
\fancyfoot[LE,RO]{{\py#HeaderFamily\thepage}}
\fancyfoot[LO]{{\py#HeaderFamily\nouppercase{\rightmark}}}
\fancyfoot[RE]{{\py#HeaderFamily\nouppercase{\leftmark}}}
\fancyhead[LE,RO]{{\py#HeaderFamily \#title, \py#release}}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}
% define chaptermark with \#chappos when \#chappos is available for Japanese
\spx#ifundefined{#chappos}{}
{\def\chaptermark##1{\markboth{\#chapapp\space\thechapter\space\#chappos\space ##1}{}}}
}
\makeatother
""",
}

Unicode characters in XeLatex

This is my LaTex script:
\documentclass[a4paper]{article}
\usepackage{fontspec}
\usepackage{xunicode}
\usepackage{xltxtra}
\setmainfont[Mapping=tex-text]{Jenson Classico}
\begin{document}
ąęśćłó
\end{document}
I compile this using xelatex through eclipse plugin.
As Jenson Classico has no polish characters I have edited this font to add them. In Microsoft Office it works fine (I am able to use polish characters). Unfortunately in pdf generated from above tex-file it doesn't. If I use any other font (e.g. Arial) it works like a dream.
Any suggesions? I really don't have any more ideas...
Try using the polyglossia package.
\documentclass[a4paper]{article}
\usepackage{fontspec}
\usepackage{polyglossia}
\usepackage{xunicode}
\usepackage{xltxtra}
\setdefaultlanguage{polish}
\setmainfont[Mapping=tex-text]{Jenson Classico}
\begin{document}
ąęśćłó
\end{document}
Use \char" followed by the Unicode value.
For example, ąęśćłó would be: \char"0105\char"0119\char"015B\char"0107\char"0142\char"00F3.

Resources