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 ask another question related to this one "Literal" numbering of chapters but not in contents which was not "precise"... This question is the exact one, with an example...

This example gives me chapters "one" and "two" in the first pages of chapters (and this is what I want), and in the contents "1" and "two" (and this isn't what I want..). I want to obtain the same thing in the text but, in the contents, "1" and "2".. Then how to change the chapterhead, to be numeric.. I want it "1.1" for the section 1 not "one.1" like in my example.

I write all the packages for preventing eventual conflicts because I use all this packages in my book (of probability in arabic)...

    \documentclass[14pt,a4paper]{extbook}%{article}%

    \usepackage{titletoc}
    \usepackage{etoolbox}
    \usepackage{multicol}
    \usepackage{amsmath,amssymb}
    \usepackage[most]{tcolorbox}
    \usepackage{boxedminipage}
    \usepackage{slashbox}
    \usepackage{titlesec}
    \usepackage{enumitem}
    \usepackage{minitoc}
    \usepackage{rotating}
    \usepackage{fmultico}
    \setlength{\columnseprule}{0.1pt}
    \usepackage{fancyhdr}
    \pagestyle{fancy}
    \usepackage{pdflscape}
    \usepackage{array}

    \usepackage{polyglossia}
    \setmainlanguage{english}
    \setotherlanguage[numerals=maghrib]{arabic}

    \makeatletter
    \let\old@makechapterhead\@makechapterhead
    \def\@makechapterhead{\def\thechapter{\words{chapter}}\old@makechapterhead}
    \makeatother

    \newcommand\words[1]{\expandafter\xwords\csname c@#1\endcsname}
    \def\xwords#1{\ifcase#1\or
    one\or          
    two\or          
    three\or            
        \else
        I need more words\fi}


    \begin{document}
    \tableofcontents
    \chapter{Simulation}
    \section{Introduction 1} 
    Simulation
    \section{Introduction 2} 
    \chapter{Simulation}
      Simulation
     \end{document}
share|improve this question
add comment

1 Answer 1

Instead of modifying the macro \thechapter that's used inside the macro \@makechapterhead, one could patch \@makechapterhead directly to make it use \words{chapter} instead of \thechapter when typesetting the representation of the chapter's "number". (The patching may be done via a \patchcmd instruction. As it looks like you're loading the etoolbox package anyway, you'll have access to \patchcmd.) By not touching the definition of \thechapter, no downstream complications result in terms of uses of \thechapter in, say, the creation of the table of contents.

Summarizing, I suggest that instead of

\makeatletter
\let\old@makechapterhead\@makechapterhead
\def\@makechapterhead{\def\thechapter{\words{chapter}}\old@makechapterhead}
\makeatother

you execute

% \usepackage{etoolbox} %% uncomment if 'etoolbox' isn't already being loaded
\makeatletter
\patchcmd{\@makechapterhead}{\thechapter}{\words{chapter}}{}{}
\makeatother

Aside: In order to get your code to compile on my system (MacOSX 10.9.2, TeXLive2104/pre with all packages fully up to date), I had to comment out the instruction \usepackage{titletoc} that's in your preamble. It looks like titletoc tries to load the inputenc package, either directly or through a subsidiary package. When compiling a document under XeLaTeX -- which seems to be the case here, since you're also loading polyglossia -- the inputenc package should not be loaded. XeLaTeX (and LuaLaTeX too, for that matter) can handle only one input encoding system: UTF8. I think that until quite recently only a warning message would be issued if you (or one of the packages you specify) loaded inputenc; with the most recent update to TeXLive an outright error message is generated and compilation hangs. Let's all hope that the titletoc package gets upgraded soon to no longer load inputenc (and especially not if running under either XeLaTeX or LuaLaTeX).

share|improve this answer
    
Thanks Mico for your very pedagogic explanation about the problems related to what I want... I tried your command which works very well in "normal" packages, but which has not any effect with polyglossia... Any way, I regret this so much because the first page of chapters is so beautiful in arabic when it's litteral.. Let's hope that the new versions of titlesec will avoid inputenc, and all be fine... Thanks –  Faouzi Bellalouna May 9 at 9:18
    
@FaouziBellalouna - I'm not sure I understand the issue. I am able to compile your MWE under XeLaTeX -- and with the polyglossia package loaded -- as long as the titletoc package is not loaded. Please elaborate what you mean by "does not have any effect". Which TeX distribution do you use, by the way? –  Mico May 9 at 9:26
    
first I want to many thank you because your question made me to study the problem deeply and see what means "does not have any effect" and why !!?? So I saw all my macros and found the reason of that, what is this... \titleformat{\chapter}[display] {\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter}{20pt}{\Huge} \titlespacing{\chapter} {0pt}{40pt}{-10pt} I don't know why I use this, I think it's connected with minitableofcontents !!... So when I comment it, all is very well !! it writes me litteral numbering for chapter... الباب الأول... الباب الثاني... –  Faouzi Bellalouna May 9 at 10:46
    
This is very more beautiful in arabic instead of ...الباب 1... الباب 2... The word الباب means "Chapter" in arabic.. So I tried for 3 or 4 chapters of my book and all seems well.. So I'm "perplexe".. what's the utility for me of what I've commented ?? why it have this effect (i.e the numbering is numeric not litteral ) ?? Many thanks another time –  Faouzi Bellalouna May 9 at 10:51
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.