2

Referring to this thread: Subsection titles (and not only) alignement with titletoc, I've a strange behaviour in a specific case. Please, consider the following code:

\documentclass[a4paper,twoside,11pt]{report}
\usepackage{fontspec}
\setmainfont{EB Garamond}
\usepackage{polyglossia}
\setmainlanguage[babelshorthands=true]{italian}
\PolyglossiaSetup{italian}{indentfirst=false}
\setotherlanguage[variant=polytonic]{greek}
\newfontfamily\greekfont[Scale=MatchLowercase]{GFS Didot}
\usepackage{microtype}
\frenchspacing
\usepackage{lipsum}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{titlesec,titletoc}
\makeatletter
\contentsmargin[-1.55em]{1.55em}
\makeatother

\titlecontents{chapter}
  [3em]
  {\vspace*{\baselineskip}\mdseries}
  {\contentslabel[\hfill\thecontentslabel]{3em}\enspace}
  {\hspace*{0.5em}}
  {\hspace*{0.5em}}
  []

\titlecontents{section}
  [3em]
  {\vspace*{\baselineskip}\mdseries}
  {\contentslabel[\hfill\thecontentslabel]{3em}\enspace}
  {}
{\hfill\llap{\makebox[\dimexpr\linewidth-1.3pc][l]{\makebox[1pc][r]{\thecontentspage}}}}
  []

\titlecontents*{subsection}
  [3.525em]
  {\footnotesize}
  {}
  {}
  {,~\thecontentspage}
  [~--~]
  []

\titleformat{\chapter}[display]
  {\normalfont\fontsize{11pt}{12pt}\selectfont}{\thechapter}{0pt}{}
\renewcommand\thesection{\arabic{section}}
\titleformat{\section}
  {\normalfont\fontsize{11pt}{12pt}\selectfont}{\thesection}{1em}{}
\titleformat{\subsection}
  {\normalfont\fontsize{11pt}{12pt}\selectfont\itshape}{\phantom{\thesection}}{1em}{}
\titlespacing{\chapter}{0pt}{0pt}{3cm}

\renewcommand{\thechapter}{\scshape\roman{chapter}}
\renewcommand{\thesection}{\arabic{section}.}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\tableofcontents

\chapter{Premessa}
\section{Section One}
\subsection{Plato}
\lipsum[1]

\begin{greek}ῥητοτορική τέχνη\end{greek}

\lipsum[2]

\subsection{Aristoteles}
\lipsum[1]

\begin{greek}ῥητοτορική τέχνη\end{greek}

\lipsum[2]

\subsection{A Title a bit longer}
\lipsum[1]

\begin{greek}ῥητοτορική τέχνη\end{greek}

\lipsum[2]

\subsection{Etimo}
La retorica è l'arte di persuadere mediante i discorsi. Il termine deriva dal
latino \emph{rhetorica} (\emph{ars}), mutuato a sua volta dal greco
\begin{greek}ῥητοτορική τέχνη\end{greek}, espressione che indica l'arte del
parlare in pubblico (\begin{greek}ῥήτωρ\end{greek}, ossia colui che parla in
a sua volta deriva dalla radice del verbo \begin{greek}εἴρω\end{greek}, «io
dico».

\subsection{Retorica e linguaggio}
Nel corso dei secoli i teorici si sono impegnati a individuare i vari elementi e
organizzarli in una tassonomia generale, senza però mai raggiungere una
classificazione condivisa.[\begin{greek}ῥητοτορική τέχνη\end{greek}] Questo
ingente numero di trattati, ha contribuito non poco alla stessa decadenza della
retorica.

\subsection{Evoluzione della retorica}
\lipsum[1]

\end{document}

Where in the text there is \begin{greek}...\end{greek}an anomalous space (asymmetrical and greater than necessary) is produced in the Table of contents, as in the pic under: enter image description here

By eliminating the Greek, everything returns to normal. I don't understand the reason of this little trouble.

How is it possible to solve, for I need to have greek text? Thanx

  • Try {\foreignlanguage{greek}ῥητοτορική τέχνη} – koleygr Nov 10 '18 at 23:12
  • you can also add \usepackage{etoc} and this will cure the problem because it auto-magically ignores end of line spaces from the toc file... (but do use egreg's answer rather, or wait until next LaTeX release :) ) – user4686 Nov 11 '18 at 11:30
3

The issue is due to the fact that each greek environment in the document writes two lines in the auxiliary files, including .toc, namely

\select@language{greek}
\select@language{italian}

These confuse the reading of the file and introduce two spaces.

You can cure this by asking LaTeX to read the .toc file without taking into account end-of-lines.

On the other hand, using \foreignlanguage for short inserts in a different language is certainly preferable. There is a shorthand for this with polyglossia, namely

\textgreek{ῥητοτορική τέχνη}

I'd also recommend defining a new environment like

\newenvironment{greek*}[1][]
  {\begin{otherlanguage*}[#1]{greek}}
  {\end{otherlanguage*}}

for longer passages in Greek, if needed.

In the code I reshaped your preamble to separate package loading and settings. I left the \begin{greek}...\end{greek}, except at one place for showing that \textgreek works.

\documentclass[a4paper,twoside,11pt]{report}
\usepackage{fontspec}
\usepackage{polyglossia}
\usepackage{microtype}
\usepackage{titlesec,titletoc}

\usepackage{lipsum}

%%% patch \@starttoc to ignore end lines
\makeatletter
\patchcmd{\@starttoc}{\begingroup}{\begingroup\endlinechar=-1\relax}{}{}
\makeatother

\setmainfont{EB Garamond}
\setmainlanguage[babelshorthands=true]{italian}
\PolyglossiaSetup{italian}{indentfirst=false}
\setotherlanguage[variant=polytonic]{greek}
\newfontfamily\greekfont[Scale=MatchLowercase]{GFS Didot}
\frenchspacing

\contentsmargin[-1.55em]{1.55em}

\titlecontents{chapter}
  [3em]
  {\vspace*{\baselineskip}\mdseries}
  {\contentslabel[\hfill\thecontentslabel]{3em}\enspace}
  {\hspace*{0.5em}}
  {\hspace*{0.5em}}
  []

\titlecontents{section}
  [3em]
  {\vspace*{\baselineskip}\mdseries}
  {\contentslabel[\hfill\thecontentslabel]{3em}\enspace}
  {}
  {\hfill\llap{\makebox[\dimexpr\linewidth-1.3pc][l]{%
   \makebox[1pc][r]{\thecontentspage}}}}
  []

\titlecontents*{subsection}
  [3.525em]
  {\footnotesize}
  {}
  {}
  {,~\thecontentspage}
  [~--~]
  []

\titleformat{\chapter}[display]
  {\normalfont\fontsize{11pt}{12pt}\selectfont}{\thechapter}{0pt}{}
\renewcommand\thesection{\arabic{section}}
\titleformat{\section}
  {\normalfont\fontsize{11pt}{12pt}\selectfont}{\thesection}{1em}{}
\titleformat{\subsection}
  {\normalfont\fontsize{11pt}{12pt}\selectfont\itshape}{\phantom{\thesection}}{1em}{}
\titlespacing{\chapter}{0pt}{0pt}{3cm}

\renewcommand{\thechapter}{\scshape\roman{chapter}}
\renewcommand{\thesection}{\arabic{section}.}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\tableofcontents

\chapter{Premessa}
\section{Section One}
\subsection{Plato}
\lipsum[1]

\textgreek{ῥητοτορική τέχνη}

\lipsum[2]

\subsection{Aristoteles}
\lipsum[1]

\begin{greek}ῥητοτορική τέχνη\end{greek}

\lipsum[2]

\subsection{A Title a bit longer}
\lipsum[1]

\begin{greek}ῥητοτορική τέχνη\end{greek}

\lipsum[2]

\subsection{Etimo}
La retorica è l'arte di persuadere mediante i discorsi. Il termine deriva dal
latino \emph{rhetorica} (\emph{ars}), mutuato a sua volta dal greco
\begin{greek}ῥητοτορική τέχνη\end{greek}, espressione che indica l'arte del
parlare in pubblico (\begin{greek}ῥήτωρ\end{greek}, ossia colui che parla in
a sua volta deriva dalla radice del verbo \begin{greek}εἴρω\end{greek}, «io
dico».

\subsection{Retorica e linguaggio}
Nel corso dei secoli i teorici si sono impegnati a individuare i vari elementi e
organizzarli in una tassonomia generale, senza però mai raggiungere una
classificazione condivisa.[\begin{greek}ῥητοτορική τέχνη\end{greek}] Questo
ingente numero di trattati, ha contribuito non poco alla stessa decadenza della
retorica.

\subsection{Evoluzione della retorica}
\lipsum[1]

\end{document}

enter image description here

In the next release of LaTeX, planned for the beginning of 2019, the issue should vanish, because all lines written to the auxiliary files by \addtocontents will basically be ended by a %.

  • thanx for your excellent (as always) explanation and solution – user41063 Nov 12 '18 at 17:52

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.