persiantex / bidi

Bidirectional typesetting in plain TeX and LaTeX, using XeTeX
https://ctan.org/pkg/bidi
7 stars 0 forks source link

Redefining \scr@dte@tocline causes failure with xetex #7

Open vafakhalighi opened 4 years ago

vafakhalighi commented 4 years ago

Brief outline of the issue

Please see this thread: https://latex.org/forum/viewtopic.php?f=19&t=33483&p=112872#p112872 I have a document with figure wrap floats that define their width as percentage of the column. When compiling, Xetex throws errors like the following:

! Missing number, treated as zero.

\scr@dte@pagenumberwidth
\scr@tso@figure@pagenumberbox ...@pagenumberwidth}
{\hfil #1}
...scr@tso@figure@pagenumberformat}{9}}
}@Par
\scr@tso@figure@entryformat #1->#1

\scr@dte@tocline ...pagenumberformat}{#3}}}@Par }
}}\tocbasic@SetPenaltyByTO...

\l@figure ...ure}\scr@dte@tocline {figure}{#1}{#2}
\TOC@EntryEndHook {figure}
\contentsline ...L \endR \fi }\hyper@linkend }{#3}
\or \csname l@#1\endcsname...
l.65 ...el of narrative rhetoric.}}{9}{figure.2.1}
%
A number should have been here; I inserted 0. (If you can't figure out why I needed to see a number, look up weird error' in the index to The TeXbook.)

! Illegal unit of measure (pt inserted).

Check/indicate

Minimal example showing the issue

\usepackage{fontspec}
\setmainfont[Mapping=tex-text,Numbers=OldStyle]{Linux Libertine O}
\setsansfont[Mapping=tex-text]{Linux Biolinum O}
\usepackage[a4paper]{geometry}
\geometry{verbose,tmargin=2cm,bmargin=2cm,lmargin=2cm,rmargin=2cm}
\usepackage{fancyhdr}
\pagestyle{fancy}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{1}
\setlength{\parskip}{\smallskipamount}
\setlength{\parindent}{0pt}
\usepackage{graphicx}

\makeatletter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
\newcommand{\noun}[1]{\textsc{#1}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Textclass specific LaTeX commands.
\newlength{\lyxlabelwidth}      % auxiliary length 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\usepackage{polyglossia}
\setdefaultlanguage[variant=american]{english}
\usepackage{bidi}
\errorcontextlines=10

\makeatother

\begin{document}
\frontmatter

\tableofcontents{}

\listoffigures

\subsection{Event-Space Ephemera}

The page of score from the work \noun{Treatise} by Cornelius Cardew,
presented in Figure \ref{fig:Page-183-from-cardews-treatise-1}, serves
as a practical example of the role secondary or ephemeral score materials
may take in the analysis. As is evident from the page, and from other
sources among Cardew's \emph{œvre},\footnote{See, for example, the work \noun{Autumn '60}, discussed in some books.}
the empty staff lines are provided as a space for performers to record
any notations they might deem pertinent to the realization. As already
noted, a diligent analysis addresses the specific instance of performance,
and this is nonsensical without including whatever notations may have
been added by the participants.\footnote{This is, for example, a notable strength of the analysis of David
Tudor's realization of \noun{Variations Ⅱ} in another book.} Such ephemera also comprise the additional materials commonly described
as sketch and manuscript sources, as well as any documentary materials
derived from rehearsal or preparatory work. 

\begin{figure}
\begin{centering}
\includegraphics[width=0.45\columnwidth]{/home/elassus/carrier1/Images/not_my_real_mom_cat}
\par\end{centering}
\caption{\label{fig:Page-183-from-cardews-treatise-1}Page 183 from \noun{Treatise}
by Cornelius Cardew}
\end{figure}

\end{document}

Expected behavior

The document actually compiles to a finished pdf, but compilation fails with the error given at the top. According to the linked thread, this is due to bidi definition of \scr@dte@tocline not having \scr@dte@pagenumberwidth defined before it's used.

I can just load the pdf, I guess, from the temp directory, but it'd be nice to get this fixed. I'm writing this with LyX, so some of the document has LyX's internal tex stuff.

Log and PDF files

muzimuzhi commented 4 years ago

A simplified example:

(I am from TeX-SX quesion https://tex.stackexchange.com/q/549846 so table instead of figure is used.)

\documentclass{scrbook}
\usepackage{bidi}

\begin{document}
\contentsline{table}{\numberline {\relax 1.1}{\ignorespaces Table title}}{1}
\end{document}

Compared to the original definition of \scr@dte@tocline in tocbasic.sty, the following change seems to fix the problem.

diff --git a/bidi.dtx b/bidi.dtx
index f0192ef..340a03a 100755
--- a/bidi.dtx
+++ b/bidi.dtx
@@ -21128,6 +21128,8 @@ to\rtside{\box\bslice\hfil}}
           {%
             \normalfont\normalsize\@nameuse{scr@tso@#1@linefill}%
             \nobreak
+            \expandafter\let\expandafter\scr@dte@pagenumberwidth
+            \csname scr@tso@#1@pagenumberwidth\endcsname
             \@nameuse{scr@tso@#1@pagenumberbox}{%
               \@nameuse{scr@tso@#1@pagenumberformat}{#3}%
             }%

Some notes:

With #1 == table in my simplified example, \@nameuse{scr@tso@#1@pagenumberbox}{...} expands to \scr@tso@table@pagenumberbox{...}, then expands to

\hb@xt@ \@nameuse {scr@dte@pagenumberwidth}{\hfil ...}

Here \scr@dte@pagenumberwidth is never defined, hence

\hb@xt@\scr@dte@pagenumberwidth{\hfil ...}

raises error ! Missing number, treated as zero.

muzimuzhi commented 4 years ago

The proposed change fixes #14 as well.