Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have come across a very peculiar problem. The sections and subsections show correctly in my output when the language is set to English. But when I change the language to Hebrew which it needs to be to display the RTL language correctly, the sections and subsections are messed up. I need to understand why this is happening and how to fix it, please.

The only change between the two examples is \setmainlanguage{english} changed to \setmainlanguage{hebrew}.

An ideal answer would use the hebrewnumerals feature, but show only the relevant subsection and section parts of the number. As in 2 instead of 1.1.2 or rather ב instead of א.א.ב

Example 1:

enter image description here

Example 2:

enter image description here

MWE: (compile it in XeLaTeX with Cardo font)

\documentclass[paper=a5,pagesize=pdftex]{scrbook}
\usepackage[top=2cm,bottom=1.5cm, left=1.5cm, right=1.5cm]{geometry}
\usepackage[pagestyles]{titlesec}
\usepackage{lettrine}
\usepackage{xltxtra}
\usepackage{tocloft}
\usepackage{etoolbox}
\usepackage[toc]{multitoc}
\usepackage{setspace}

\renewcommand{\thesection}{\arabic{section}}
\renewcommand{\thesubsection}{\arabic{subsection}}

\setcounter{tocdepth}{0}
\setcounter{secnumdepth}{2}

\defaultfontfeatures{Mapping=tex-text}
\setmainfont{Cardo}

% sets the marks to be used (section and subsection)
\setmarks{section}{subsection}

\newlength\howwide

\newcommand\defhowwide{
    \ifnumless{\value{section}}{99}{\ifnumgreater{\value{section}}{8}{\setlength{\howwide}{2.5em}}{\setlength{\howwide}{1.2em}}}{\ifnumgreater{\value{section}}{98}{\setlength{\howwide}{3.5em}}{\setlength{\howwide}{2.5em}}}
}

% sections and subsections formatting
\titleformat{\section}{}{\lettrine{\thesection}}{0em}{}[\vskip-1\baselineskip]
\titleformat{\subsection}[runin]{\small\bfseries}{\thesubsection}{1em}{}
\titlespacing{\section}{\howwide}{-1pt}{0pt}
\titlespacing{\subsection}{0pt}{0pt}{1em}

\setlength{\parindent}{0pt}

\newlength\NumLen
\newlength\LinLen
% indents one line of text. Indentation= width of section number + 1em
\newcommand\IndOne{%
  \setlength\NumLen{\howwide}
  \addtolength\NumLen{0.5em}
  \setlength\LinLen{\dimexpr\textwidth-\NumLen}%\the\NumLen\the\LinLen
  \parshape 2 \NumLen \LinLen 0pt \textwidth}
% indents two lines of text. Indentation= width of section number + 1em
\newcommand\IndTwo{%
  \setlength\NumLen{\howwide}
  \addtolength\NumLen{0.5em}
  \setlength\LinLen{\dimexpr\textwidth-\NumLen}%\the\NumLen\the\LinLen
  \parshape 3 \NumLen \LinLen \NumLen \LinLen 0pt \textwidth}

\usepackage{polyglossia} 
   \setmainlanguage{english} 
   \setotherlanguage{english}

\begin{document}

\mainmatter

\newlength{\myIndent}
\setcounter{section}{0}

\addtocounter{chapter}{1}

\setcounter{section}{0}
\defhowwide
\section{}
\settowidth{\myIndent}
{\IndOne בְּרֵאשִׁית בָּרָא אֱלֹהִים אֵת הַשָּׁמַיִם וְאֵת הָאָרֶץ׃}
\ifdimless{\the\myIndent}
{\textwidth-\howwide+0.75em}
{\IndOne בְּרֵאשִׁית בָּרָא אֱלֹהִים אֵת הַשָּׁמַיִם וְאֵת הָאָרֶץ׃ \stepcounter{subsection}
\subsection{} \IndOne וְהָאָרֶץ הָיְתָה תֹהוּ וָבֹהוּ וְחֹשֶׁךְ עַל־פְּנֵי תְהֹום וְרוּחַ אֱלֹהִים מְרַחֶפֶת עַל־פְּנֵי הַמָּיִם׃}
{\IndTwo בְּרֵאשִׁית בָּרָא אֱלֹהִים אֵת הַשָּׁמַיִם וְאֵת הָאָרֶץ׃ \stepcounter{subsection} \subsection{} וְהָאָרֶץ הָיְתָה תֹהוּ וָבֹהוּ וְחֹשֶׁךְ עַל־פְּנֵי תְהֹום וְרוּחַ אֱלֹהִים מְרַחֶפֶת עַל־פְּנֵי הַמָּיִם׃}
\subsection{} וַיֹּאמֶר אֱלֹהִים יְהִי אֹור וַיְהִי־אֹור׃
\end{document}
share|improve this question
1  
Try putting all your command definitions after loading polyglossia and setting the languages. –  Alan Munn Mar 12 '12 at 15:21
    
@AlanMunn: Great thanks. It works. If you can put it as an answer I can accept it. –  McGafter Mar 12 '12 at 15:40
add comment

1 Answer 1

up vote 3 down vote accepted

The main problem is probably that you are defining commands before you load polyglossia. Since polyglossia loads the bidi package when you select an RTL language, and bidi does all sorts of modifications to package commands, it's important to do all of your own modifications after loading polyglossia and setting the language.

In general, this is good practice independent of polyglossia: first load packages, then do command (re)definitions.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.