[latex3-commits] [git/latex2e] master: Starting with bidi layout (unstable) (f52c382)

Javier javier at dante.de
Sun Dec 10 13:08:37 CET 2017


Repository : https://github.com/latex3/latex2e
On branch  : master
Link       : https://github.com/latex3/latex2e/commit/f52c382f2dbfb1c98039a8fc84017a40c703a563

>---------------------------------------------------------------

commit f52c382f2dbfb1c98039a8fc84017a40c703a563
Author: Javier <javier at localhost>
Date:   Sun Dec 10 13:07:13 2017 +0100

    Starting with bidi layout (unstable)


>---------------------------------------------------------------

f52c382f2dbfb1c98039a8fc84017a40c703a563
 required/babel/babel.dtx |  354 +++++++++++++++++++++++++++++++++++++++++-----
 required/babel/babel.ins |    1 +
 required/babel/babel.pdf |  Bin 606604 -> 609982 bytes
 3 files changed, 316 insertions(+), 39 deletions(-)

diff --git a/required/babel/babel.dtx b/required/babel/babel.dtx
index e8fb2ad..539b70f 100644
--- a/required/babel/babel.dtx
+++ b/required/babel/babel.dtx
@@ -226,8 +226,9 @@ Javier Bezos
 This user guide focuses on \LaTeX. There are also some notes on its
 use with Plain \TeX.
 
-If you are interested in the \TeX{} multilingual support, please join the
-\textsf{kadingira} list on \texttt{http://tug.org/mailman/listinfo/kadingira}.
+If you are interested in the \TeX{} multilingual support, please join
+the \textsf{kadingira} list on
+\texttt{http://tug.org/mailman/listinfo/kadingira}.
 
 \section{The user interface}\label{U-I}
 
@@ -2103,8 +2104,8 @@ ones, they only have a single hook and replace a default definition.
 \end{description}
 
 \Describe\BabelContentsFiles{}
-\New{3.9a} This macro contains a list of ``toc'' types which
-require a command to switch the language. Its default value is
+\New{3.9a} This macro contains a list of ``toc'' types 
+requiring a command to switch the language. Its default value is
 |toc,lof,lot|, but you may redefine it with |\renewcommand| (it's up
 to you to make sure no toc type is duplicated).
 
@@ -2233,13 +2234,6 @@ fonts (for example, if the main latin encoding was |LY1|), and
 therefore it has been deprecated.\footnote{But still defined for
 backwards compatibility.}
 
-No macros to select the writing direction are provided, either --
-writing direction is intrinsic to each script and therefore it is best
-set by the language (which could be a dummy one). Furthermore, there
-are in fact two right-to-left modes, depending on the language, which
-differ in the way `weak' numeric characters are ordered (eg, Arabic
-\%123 \textit{vs} Hebrew 123\%).
-
 \Describe{\ensureascii}{\marg{text}}
 
 \New{3.9i} This macro makes sure \m{text} is typeset with a
@@ -2264,6 +2258,36 @@ most of cases. No asumption is made on characters above
 127, which may not follow the LICR conventions -- the goal is just
 to ensure most of the ASCII letters and symbols are the right ones.
 
+\subsection{Selecting directions}
+
+No macros to select the writing direction are provided, either --
+writing direction is intrinsic to each script and therefore it is best
+set by the language (which could be a dummy one). Furthermore, there
+are in fact two right-to-left modes, depending on the language, which
+differ in the way `weak' numeric characters are ordered (eg, Arabic
+\%123 \textit{vs} Hebrew 123\%).
+
+However, digits in \textsc{pdftex} must be marked up explicitly
+(unlike \luatex{} with |bidi=basic-r| and, usually, \xetex{}). For it
+(although available in all engines), the following command is
+provided:
+
+\Describe{\babelsublr}{\marg{lr-text}}
+
+Set \marg{lr-text} in L mode. It's mainly intended for what Unicode
+calls weak characters, because words are best set with the
+corresponding language. For this reason, there is not a |rl|
+counterpart.
+
+\begin{warning}
+  Setting bidi text has many subtleties (see for example
+  <https://www.w3.org/TR/html-bidi/>). This means the \babel{} bidi
+  code may take some time before it is truly stable. An effort is
+  being made to avoid incompatibilities in the future (this one of the
+  reason currently bidi must be explicitly requested as a package
+  option, with a certain bidi model).
+\end{warning}
+
 \subsection{Language attributes}
 
 \DescribeMacro{\languageattribute}
@@ -3175,7 +3199,7 @@ optional one. This command, unlike |\SetString|, is executed always
 only.
 
 For example, as |T1| is the default case mapping in \LaTeX, we could
-set for Turkish: % :-( Seem to be a bug in listings. Fixed with &&.
+set for Turkish:
 \begin{verbatim}
 \StartBabelCommands{turkish}{}[ot1enc, fontenc=OT1]
 \SetCase
@@ -3922,7 +3946,7 @@ help from Bernd Raichle, for which I am grateful.
 %    and assigned to |\BabelModifiers| at |\bbl at load@language|; when
 %    no modifiers have been given, the former is |\relax|. How
 %    modifiers are handled are left to language styles; they can use
-%    |\in@|, loop them with |\@for| or load |keyval|, for example).
+%    |\in@|, loop them with |\@for| or load |keyval|, for example.
 %
 % \changes{babel~3.9e}{2013/04/15}{Bug fixed - a dot was added in
 %    key=value pairs}
@@ -3947,11 +3971,11 @@ help from Bernd Raichle, for which I am grateful.
 \expandafter\let\csname opt at babel.sty\endcsname\bbl at tempc
 %    \end{macrocode}
 %
-%    The next option tells \babel\ to leave shorthand characters
-%    active at the end of processing the package. This is \emph{not}
-%    the default as it can cause problems with other packages, but for
-%    those who want to use the shorthand characters in the preamble of
-%    their documents this can help.
+% The next option tells \babel\ to leave shorthand characters active
+% at the end of processing the package. This is \emph{not} the default
+% as it can cause problems with other packages, but for those who want
+% to use the shorthand characters in the preamble of their documents
+% this can help.
 %
 % \changes{babel~3.9a}{2012/08/14}{Implemented the \texttt{noconfigs}
 %    option}
@@ -3987,6 +4011,7 @@ help from Bernd Raichle, for which I am grateful.
 \let\bbl at opt@config\@nnil
 \let\bbl at opt@main\@nnil
 \let\bbl at opt@headfoot\@nnil
+\let\bbl at opt@layout\@nnil
 %    \end{macrocode}
 %
 % The following tool is defined temporarily to store the values of
@@ -4005,11 +4030,11 @@ help from Bernd Raichle, for which I am grateful.
   \fi}
 %    \end{macrocode}
 %
-%    Now the option list is processed, taking into account only
-%    currently declared options (including those declared with a |=|),
-%    and |<key>=<value>| options (the former take precedence). 
-%    Unrecognized options are saved in |\bbl at language@opts|, because
-%    they are language options. 
+% Now the option list is processed, taking into account only currently
+% declared options (including those declared with a |=|), and
+% |<key>=<value>| options (the former take precedence).  Unrecognized
+% options are saved in |\bbl at language@opts|, because they are language
+% options.
 %
 %    \begin{macrocode}
 \let\bbl at language@opts\@empty
@@ -4120,6 +4145,23 @@ help from Bernd Raichle, for which I am grateful.
 \fi
 %    \end{macrocode}
 %
+% For |layout| an auxiliary macro is provided, available for packages
+% and language styles.
+%
+%    \begin{macrocode}
+\ifx\bbl at opt@layout\@nnil
+  \newcommand\IfBabelLayout[3]{#3}%
+\else
+  \newcommand\IfBabelLayout[1]{%
+    \@expandtwoargs\in@{.#1.}{.\bbl at opt@layout.}%
+    \ifin@
+      \expandafter\@firstoftwo
+    \else
+      \expandafter\@secondoftwo
+    \fi}
+\fi
+%    \end{macrocode}
+%
 % \subsection{Language options}
 %
 % \changes{babel~3.9a}{2012/06/15}{Rewritten the loading mechanism, so
@@ -4820,7 +4862,8 @@ help from Bernd Raichle, for which I am grateful.
 %
 %    \begin{macrocode}
 \AtBeginDocument{%
-  \expandafter\selectlanguage\expandafter{\bbl at main@language}}
+  \expandafter\selectlanguage\expandafter{\bbl at main@language}%
+  \ifcase\bbl at engine\or\pagedir\bodydir\fi}  % TODO - a better place
 %    \end{macrocode}
 %
 %  \end{macro}
@@ -7105,7 +7148,9 @@ help from Bernd Raichle, for which I am grateful.
 %    Now we load definition files for engines.
 %
 %    \begin{macrocode}
-\ifcase\bbl at engine\or
+\ifcase\bbl at engine
+  \input txtbabel.def
+\or
   \input luababel.def
 \or
   \input xebabel.def
@@ -7525,8 +7570,8 @@ help from Bernd Raichle, for which I am grateful.
         \def\bbl at iniline########1\bbl at iniline{}}%
       \catcode`\[=12 \catcode`\]=12 \catcode`\==12 
       \bbl at read@ini{##1}%
-    \endgroup}
-  \InputIfFileExists{babel-#1.tex}{}{}}
+    \endgroup}%           boxed, to avoid extra spaces:
+  \setbox\z@\hbox{\InputIfFileExists{babel-#1.tex}{}{}}}
 %    \end{macrocode}
 %
 % \subsection{Cross referencing macros}
@@ -8380,12 +8425,11 @@ help from Bernd Raichle, for which I am grateful.
   \bbl at exp{\\\bbl at setdirs\bbl at cs{wdir@\languagename}}}
 \def\bbl at setdirs#1{% TODO - math
   \ifcase\bbl at select@type % TODO - strictly, not the right test
-    \bbl at pagedir{#1}%
     \bbl at bodydir{#1}%
     \bbl at pardir{#1}%
   \fi
   \bbl at textdir{#1}}
-\ifodd\bbl at engine
+\ifodd\bbl at engine  % luatex=1
   \AddBabelHook{babel-bidi}{afterextras}{\bbl at switchdir}
   \DisableBabelHook{babel-bidi}
   \def\bbl at getluadir#1{%
@@ -8412,7 +8456,7 @@ help from Bernd Raichle, for which I am grateful.
   \def\bbl at bodydir{\bbl at setdir{body}\bodydir}
   \def\bbl at pagedir{\bbl at setdir{page}\pagedir}
   \def\bbl at dirparastext{\pardir\the\textdir\relax}%   %%%%
-\else
+\else % pdftex=0, xetex=2
   \AddBabelHook{babel-bidi}{afterextras}{\bbl at switchdir}
   \DisableBabelHook{babel-bidi}
   \newcount\bbl at dirlevel
@@ -8481,6 +8525,12 @@ help from Bernd Raichle, for which I am grateful.
 \fi
 %    \end{macrocode}
 %  
+% A tool for weak L (mainly digits).
+%
+%    \begin{macrocode}
+\DeclareRobustCommand\babelsublr[1]{\leavevmode{\bbl at textdir\z@#1}}
+%    \end{macrocode}
+%
 % \subsection{Local Language Configuration}
 %
 %  \begin{macro}{\loadlocalcfg}
@@ -8799,9 +8849,7 @@ help from Bernd Raichle, for which I am grateful.
   \select at language{\languagename}%
   \expandafter\ifx\csname date\languagename\endcsname\relax\else
     \if at filesw
-      \protected at write\@auxout{}{\string\select at language{\languagename}}%
-      \bbl at foreach\BabelContentsFiles{%
-        \addtocontents{##1}{\xstring\select at language{\languagename}}}%
+      \protected at write\@auxout{}{\string\babel at aux{\languagename}{}}%
       \bbl at usehooks{write}{}%
     \fi
   \fi}
@@ -8821,6 +8869,12 @@ help from Bernd Raichle, for which I am grateful.
       \let\bbl at select@type\z@
       \expandafter\bbl at switch\expandafter{\languagename}%
     \fi}}
+\def\babel at aux#1#2{%
+  \select at language{#1}%
+  \bbl at foreach\BabelContentsFiles{%
+    \@writefile{##1}{\babel at toc{#1}{#2}}}} %% TODO - ok in plain? \string?
+\def\babel at toc#1#2{%
+  \select at language{#1}{#2}}
 %    \end{macrocode}
 %    
 % A bit of optimization. Select in heads/foots the language only if
@@ -9827,13 +9881,15 @@ help from Bernd Raichle, for which I am grateful.
 %    \begin{macrocode}
 %<<*More package options>>
 \DeclareOption{bidi=basic-r}%
-  {\newattribute\bbl at attr@dir
-   \let\bbl at beforeforeign\leavevmode
+  {\let\bbl at beforeforeign\leavevmode
+   \newattribute\bbl at attr@dir
+   \bbl at exp{\output{\bodydir\pagedir\the\output}}%
    \AtEndOfPackage{\EnableBabelHook{babel-bidi}}}
 \DeclareOption{bidi=default}%
   {\let\bbl at beforeforeign\leavevmode
    \ifodd\bbl at engine
      \newattribute\bbl at attr@dir
+     \bbl at exp{\output{\bodydir\pagedir\the\output}}%
    \fi
    \AtEndOfPackage{%
      \EnableBabelHook{babel-bidi}%
@@ -10083,9 +10139,154 @@ help from Bernd Raichle, for which I am grateful.
 \AddBabelHook{babel-fontspec}{afterextras}{\bbl at switchfont}
 \DisableBabelHook{babel-fontspec}
 <@Font selection@>
+\input txtbabel.def
 %</xetex>
 %    \end{macrocode}
 %
+% \subsection{Layout}
+%
+% Unfortunately, for proper support for \xetex{} lots of macros and
+% packages must be patched somehow. At least at this stage, \babel{}
+% will not do it and therefore a package similar to \textsf{bidi} will
+% be required. Any help in making \babel{} and \textsf{bidi}
+% collaborate will be wlecome. Note as well, elements like headlines
+% and margins can be modified easily with packages like
+% \textsf{fancyhdr}, \textsf{typearea} or \textsf{titleps}, and
+% \textsf{geometry}.
+%
+% |\bbl at startskip| and |\bbl at endskip| are available to package
+% authors. Thanks to the \TeX{} expansion mechanims the following
+% constructs are valid: |\adim\bbl at startskip|,
+% |\advance\bbl at startskip\adim|, |\bbl at startskip\adim|.
+%
+% Consider |txtbabel| as shorthand for \textit{tex--xet babel}.
+%
+%    \begin{macrocode}
+%<*texxet>
+\ifx\bbl at opt@layout\@nil\endinput\fi  % No layout
+\def\bbl at startskip{\ifcase\bbl at thepardir\leftskip\else\rightskip\fi}
+\def\bbl at endskip{\ifcase\bbl at thepardir\rightskip\else\leftskip\fi}
+\def\@hangfrom#1{%
+  \setbox\@tempboxa\hbox{{#1}}%
+  \hangindent\ifcase\bbl at thepardir\wd\@tempboxa\else-\wd\@tempboxa\fi
+  \noindent\box\@tempboxa}
+\def\raggedright{%
+  \let\\\@centercr
+  \bbl at startskip\z at skip
+  \@rightskip\@flushglue
+  \bbl at endskip\@rightskip
+  \parindent\z@
+  \parfillskip\bbl at startskip}
+\def\raggedleft{%
+  \let\\\@centercr
+  \bbl at startskip\@flushglue
+  \bbl at endskip\z at skip
+  \parindent\z@
+  \parfillskip\bbl at endskip}
+\IfBabelLayout{lists}
+  {\def\list#1#2{%
+    \ifnum \@listdepth >5\relax
+      \@toodeep
+    \else
+      \global\advance\@listdepth\@ne
+    \fi
+    \rightmargin\z@
+    \listparindent\z@
+    \itemindent\z@
+    \csname @list\romannumeral\the\@listdepth\endcsname
+    \def\@itemlabel{#1}%
+    \let\makelabel\@mklab
+    \@nmbrlistfalse
+    #2\relax
+    \@trivlist
+    \parskip\parsep
+    \parindent\listparindent
+    \advance\linewidth-\rightmargin
+    \advance\linewidth-\leftmargin
+    \advance\@totalleftmargin
+      \ifcase\bbl at thepardir\leftmargin\else\rightmargin\fi
+    \parshape\@ne\@totalleftmargin\linewidth
+    \ignorespaces}%
+  \def\labelenumii{)\theenumii(}%
+  \def\p at enumiii{\p at enumii)\theenumii(}}
+  {}
+\IfBabelLayout{contents}
+  {\def\@dottedtocline#1#2#3#4#5{%
+     \ifnum#1>\c at tocdepth\else
+       \vskip \z@ \@plus.2\p@
+       {\bbl at startskip#2\relax
+        \bbl at endskip\@tocrmarg
+        \parfillskip-\bbl at endskip
+        \parindent#2\relax
+        \@afterindenttrue
+        \interlinepenalty\@M
+        \leavevmode
+        \@tempdima#3\relax
+        \advance\bbl at startskip\@tempdima
+        \null\nobreak\hskip-\bbl at startskip
+        {#4}\nobreak
+        \leaders\hbox{%
+          $\m at th\mkern\@dotsep mu\hbox{.}\mkern\@dotsep mu$}%
+          \hfill\nobreak
+          \hb at xt@\@pnumwidth{\hfil\normalfont\normalcolor#5}%
+          \par}%
+     \fi}%
+   \def\babel at toc#1{%
+     \select at language{#1}%
+     \bbl at ifunset{bbl at wdir@\bbl at main@language}%
+       {\bbl at provide@dirs{\bbl at main@language}}%
+       {}%
+     \bbl at exp{%
+       \\\bbl at pardir\bbl at cs{wdir@\bbl at main@language}%
+       \\\bbl at textdir\bbl at cs{wdir@\bbl at main@language}}}}
+  {}
+\IfBabelLayout{columns}
+  {\def\@outputdblcol{%
+     \if at firstcolumn
+       \global\@firstcolumnfalse
+       \global\setbox\@leftcolumn\copy\@outputbox
+       \splitmaxdepth\maxdimen
+       \vbadness\maxdimen
+       \setbox\@outputbox\vbox{\unvbox\@outputbox\unskip}%
+       \setbox\@outputbox\vsplit\@outputbox to\maxdimen
+       \toks@\expandafter{\topmark}%
+       \xdef\@firstcoltopmark{\the\toks@}%
+       \toks@\expandafter{\splitfirstmark}%
+       \xdef\@firstcolfirstmark{\the\toks@}%
+       \ifx\@firstcolfirstmark\@empty
+         \global\let\@setmarks\relax
+       \else
+         \gdef\@setmarks{%
+           \let\firstmark\@firstcolfirstmark
+           \let\topmark\@firstcoltopmark}%
+       \fi
+     \else
+       \global\@firstcolumntrue
+       \setbox\@outputbox\vbox{%
+         \hb at xt@\textwidth{%
+           \hskip\columnwidth
+           \hfil
+           {\normalcolor\vrule \@width\columnseprule}%
+           \hfil
+           \hb at xt@\columnwidth{\box\@leftcolumn \hss}%
+           \hskip-\textwidth
+           \hb at xt@\columnwidth{\box\@outputbox \hss}%
+           \hskip\columnsep
+           \hskip\columnwidth}}%
+       \@combinedblfloats
+       \@setmarks
+       \@outputpage
+       \begingroup
+         \@dblfloatplacement
+         \@startdblcolumn
+         \@whilesw\if at fcolmade \fi{\@outputpage
+         \@startdblcolumn}%
+       \endgroup
+     \fi}}%
+  {}
+%</texxet>
+%    \end{macrocode}
+%
 % \subsection{LuaTeX}
 %
 % The new loader for luatex is based solely on |language.dat|, which
@@ -10455,16 +10656,91 @@ help from Bernd Raichle, for which I am grateful.
 \AddBabelHook{babel-fontspec}{afterextras}{\bbl at switchfont}
 \DisableBabelHook{babel-fontspec}
 <@Font selection@>
-%</luatex>
 %    \end{macrocode}
 %
 %    \section{Bidi support in \luatex}
 %
 % \changes{3.14}{2017/09/30}{LuaTeX - support for R/AL texts - basic-r}
 %
-% \textbf{Work in progress}. The file \textsf{babel-bidi.lua}
-% currently only contains data. It's a large and boring file and it's
-% not shown here. See the generated file.
+% \textbf{Work in progress}.
+%
+% \subsection{Layout}
+%
+% Unlike \xetex{}, \luatex{} requires only minimal changes for
+% right-to-left layouts, particularly in monolingual documents (the
+% engine itself reverses boxes -- including column order or headings
+% --, margins, etc.) and with |bidi=basic-r|, without having to patch
+% almost any macro where text direction is relevant.
+%
+% |\@hangfrom| is useful in many contexts and it is redefined always
+% with the |layout| option. 
+%
+% There are, however, a number of issues when the text direction is
+% not the same as the box direction (as set by |\bodydir|), and when
+% |\parbox| and |\hangindent| are involved. Fortunately, latest
+% releases of \luatex{} simplify a lot the solution with |\shapemode|.
+%
+%    \begin{macrocode}
+\ifx\bbl at opt@layout\@nil\endinput\fi  % No layout
+\def\@hangfrom#1{%
+  \setbox\@tempboxa\hbox{{#1}}%
+  \hangindent\wd\@tempboxa
+  \ifnum\bbl at getluadir{page}=\bbl at getluadir{par}\else
+    \shapemode\@ne
+  \fi
+  \noindent\box\@tempboxa}
+\IfBabelLayout{sectioning} 
+  {}
+  {}
+\IfBabelLayout{lists}
+  {\def\list#1#2{%
+     \ifnum \@listdepth >5\relax
+       \@toodeep
+     \else
+       \global\advance\@listdepth\@ne
+     \fi
+     \rightmargin\z@
+     \listparindent\z@
+     \itemindent\z@
+     \csname @list\romannumeral\the\@listdepth\endcsname
+     \def\@itemlabel{#1}%
+     \let\makelabel\@mklab
+     \@nmbrlistfalse
+     #2\relax
+     \@trivlist
+     \parskip\parsep
+     \parindent\listparindent
+     \advance\linewidth -\rightmargin
+     \advance\linewidth -\leftmargin
+     \advance\@totalleftmargin \leftmargin
+     \parshape \@ne
+     \@totalleftmargin \linewidth
+     \ifnum\bbl at getluadir{page}=\bbl at getluadir{par}\else
+       \shapemode\tw@
+     \fi
+     \ignorespaces}}
+  {}
+\IfBabelLayout{contents}
+  {\def\babel at toc#1{%
+     \select at language{#1}%
+     \bbl at ifunset{bbl at wdir@\bbl at main@language}%
+       {\bbl at provide@dirs{\bbl at main@language}}%
+       {}%
+     \bbl at exp{%
+       \\\bbl at pardir\bbl at cs{wdir@\bbl at main@language}%
+       \\\bbl at textdir\bbl at cs{wdir@\bbl at main@language}}}}
+  {}
+% only if bidi=default %%%%%%%%%%%%%%%% :
+% \def\labelenumii{)\theenumii(}  % luas, pdf, no xe, luar
+% \def\p at enumiii{\p at enumii)\theenumii(} % luas, pdf, no xe, luar
+%</luatex>
+%    \end{macrocode}
+%
+% \subsection{Auto bidi with \texttt{basic-r}}
+%
+% The file \textsf{babel-bidi.lua} currently only contains data. It's
+% a large and boring file and it's not shown here. See the generated
+% file.
 %\iffalse
 %    \begin{macrocode}
 %<*bidi> 
diff --git a/required/babel/babel.ins b/required/babel/babel.ins
index 21148e6..23e4c6b 100644
--- a/required/babel/babel.ins
+++ b/required/babel/babel.ins
@@ -137,6 +137,7 @@
           \file{nil.ldf}{\from{babel.dtx}{nil}}
           \file{xebabel.def}{\from{babel.dtx}{xetex}}
           \file{luababel.def}{\from{babel.dtx}{luatex}}
+          \file{txtbabel.def}{\from{babel.dtx}{texxet}}
           }
 
 % Support for plain users
diff --git a/required/babel/babel.pdf b/required/babel/babel.pdf
index dd72215..2b00c63 100644
Binary files a/required/babel/babel.pdf and b/required/babel/babel.pdf differ





More information about the latex3-commits mailing list