Support for RTL and bidirectional documents in OpTeX #132
Replies: 12 comments 36 replies
-
It should be very interesting to implement support for bi-directional documents for OpTeX. I haven't need more yet than to apply |
Beta Was this translation helpful? Give feedback.
-
Indeed section 3.3 is not very detailed, nor close to be complete. I found a nice explanation about Both Since \_pagerightoffset =0pt
\fontfam [newcm]
\textdir TRT\pardir TRT\pagedir TRT\bodydir TRT
\margins/1 a4 (7,7,,,)cm
שלום
\bye You can see how changing the value of the left margin or right margin doesn't affect the output. It can be fixed in the following manner \_pagerightoffset =0pt
\_def\margins/#1 #2 (#3,#4,#5,#6)#7 {\_def\_tmp{#7}%
\_ifx\_tmp\_empty
\_opwarning{\_string\_margins: missing unit, mm inserted}\_def\_tmp{mm}\_fi
\_setpagedimens #2 % setting \_pgwidth, \_pgheight
\_ifdim\_pgwidth=0pt \_else
\_hoffset=0pt \_voffset=0pt \_pagerightoffset =0pt
\_if$#3$\_if$#4$\_hoffset =\_dimexpr (\_pgwidth -\_hsize)/2 \_relax
\_pagerightoffset =\_dimexpr \_hoffset -1in \_relax
\_else \_hoffset =\_dimexpr \_pgwidth -\_hsize - #4\_tmp \_relax % only right margin
\_pagerightoffset =\_dimexpr \_hoffset -1in \_relax
\_fi
\_else \_if$#4$\_hoffset = #3\_tmp \_relax % only left margin
\_pagerightoffset =\_dimexpr \_hoffset -1in \_relax
\_else \_hsize =\_dimexpr \_pgwidth - #3\_tmp - #4\_tmp \_relax % left+right margin
\_hoffset = #3\_tmp \_relax
\_pagerightoffset =\_dimexpr \_hoffset -1in \_relax
\_xhsize =\_hsize \_setxhsize % \_xhsize used by \output routine
\_fi\_fi
\_if$#5$\_if$#6$\_voffset =\_dimexpr (\_pgheight -\_vsize)/2 \_relax
\_else \_voffset =\_dimexpr \_pgheight -\_vsize - #6\_tmp \_relax % only bottom margin
\_fi
\_else \_if$#6$\_voffset = #5\_tmp \_relax % only top margin
\_else \_vsize=\_dimexpr \_pgheight - #5\_tmp - #6\_tmp \_relax % top+bottom margin
\_voffset = #5\_tmp \_relax
\_fi\_fi
\_if 1#1\_shiftoffset=0pt \_def\_prepoffsets{}\_else \_if 2#1% double-page layout
\_shiftoffset = \_dimexpr \_pgwidth -\_hsize -2\_hoffset \_relax
\_def\_prepoffsets{\_ifodd\_pageno \_else \_advance\_hoffset \_shiftoffset \_fi}%
\_else \_opwarning{use \_string\_margins/1 or \_string\_margins/2}%
\_fi\_fi\_fi
}
\fontfam [newcm]
\textdir TRT\pardir TRT\pagedir TRT\bodydir TRT
\margins/1 a4 (7,,,,)cm
שלום
\bye Note that I did not address double page layout and that the meaning of the arguments of |
Beta Was this translation helpful? Give feedback.
-
Yes, I did read from section 3.3 that |
Beta Was this translation helpful? Give feedback.
-
As always, why questions are hard to answer, but to be more concrete, my guess is that it was more important when more directions were implemented. LuaTeX implemented the multi-directional model from the Omega and Alpha projects, and originally there were 16 possible directions, not just 4. Maybe it was just easier to separate the offsets to several registers and read an offset register at shipout in correlation to the current As for why there is a need for both I don't think there is any documentation for this topic, maybe to best source for answers would be LuaTeX's mailing list. Probably Javier Bezos has some better understanding than me on the subject, as he implemented a package meant to be used with Aleph (If I remember correctly this package is called |
Beta Was this translation helpful? Give feedback.
-
I tried to do some changes in OpTeX macros, see my last commit 56fd378. |
Beta Was this translation helpful? Give feedback.
-
I've tried the new commit on a document I'm working on and the output looks great. I don't think that the information you have added to the documentation is entirely true. Consider the following document: \textdir TRT
Just some text to fill the paragraph Just some text to fill the paragraph Just some text to fill the paragraph Just some text to fill the paragraph Just some text to fill the paragraph Just some text to fill the paragraph Just some text to fill the paragraph Just some text to fill the paragraph.
\bye As you can see, the lines don't run outside the paper. What you are describing is more similar to a situation where Slide 9 of the presentation I linked previously contain a demonstration what happens when Note that there is still some problem in the output routine, but I could not trace the source of it. When
which from the reason describe earlier, causing the body to be positioned outside of the page. Here is a minimal example:
If I uncomment the first line, the output is correct (except the are no colors, of course), so I guess Currently I'm adding to my document
so that I could use colors, I didn't encounter any problems with this hack so far, but it does not really explains what happens. The other solution I suggested for that, using
caused some problems, for example when I had overfull
|
Beta Was this translation helpful? Give feedback.
-
When I use your example
then the lines run outside the paper in my PDF output. First of all, we need exact documentation of primitives |
Beta Was this translation helpful? Give feedback.
-
I tried a second attempt to solve this issue. 1056c12 |
Beta Was this translation helpful? Give feedback.
-
Everything relevant I could find: https://ctan.org/tex-archive/obsolete/systems/omega (some information in the README, something maybe also in the http://www.pragma-ade.nl/general/manuals/aleph.pdf http://www.pragma-ade.nl/general/manuals/followingup.pdf (Chapter 6: Directions) The last one is about changes in LuaMetaTeX, but mentions some history and workings of LuaTeX / Omega. |
Beta Was this translation helpful? Give feedback.
-
If I understand well, Hebrew doesn't use hyphenation. OK, I added Hebrew to the lang-decl.opm with dummy hyphenation patterns in my last commit. It would be good to create the |
Beta Was this translation helpful? Give feedback.
-
IMHO, the RL printing using OpTeX macros is solved after my last commit with Usage of luabidi is another issue. I can imagine that a |
Beta Was this translation helpful? Give feedback.
-
Yes, I'm sincerely apologize it took so long, I was certain I've provided the example file already. In any case, I've made a pull request with an example file, I filled all the necessary data for hebrew in
You are probably right. I've had some success with Khaled Hosny's code, but it has a lot of bugs. It seems that implementing the bidi algorithm in pure lua is not an easy task. Unrelated to that, I think that OpTeX should assign two registers called |
Beta Was this translation helpful? Give feedback.
-
Hello OpTeX users,
I've started to take an interest in the OpTeX format, and as a native Hebrew speaker one of the first things I've wondered after reading the documentation and the source is if OpTeX can be used to typeset RTL documents.
I decided to start this discussion to share the problems I've encountered and possible solutions to them (luckily OpTeX's source is pretty elegant and easy to patch for such a task). I started to work on a package, I'll share it when it will be ready.
As a side note, I was really surprised how easy it was to get a working RTL document, as it is not a trivial thing and I found no indication that OpTeX was meant for that. It seems that allot of things that usually break with latex works here "out of the box".
Problems
The first thing I've observed is that the text block is not centered when
\pagedirection=1
. Since OpTeX sets\_pdfhorigin
to get rid of the annoying1in
from\_hoffset
, it means that that the default\_pagerightoffset=1in
is not desired, and should be changed to\_pagerightoffset=0pt
.The
\margins
macro does not take into account\_pagerightoffset
. It could be easily solved by adding after each assignment of\_hoffset
, assignment of\_pagerightoffset
to the same length minus1in
.It seems that if the page is shipped while
\textdir
is not the same as\pagedir
it somehow changes\bodydir
in the output routine. my suspicion is that it is somehow related to the operation that\_preshipout
do, since if I remove it it does not happen. I was able to solve it by adding\boxdirection0=\pagedirection
before\_shipout\_box0
, or by adding\textdirection=\pagedirection
somewhere before the call of\_preshipout
. I believe that the former solution is better, but I'm not fully sure why it happened in the first place, if someone can shed more light on that topic it would be great.Some adjustment to the formatting of the output routine are needed, mainly just adding conditionals to use
\_pagerightoffset
instead of\_hoffset
for the calculations when\pagedirection=1
.I guess that
\url
should be patched as well, as normally it should be typeset LTR unrelated to\textdir
, but I did not try anything yet.Counters are displayed RL inside RL context, when they should not. fix that by adding conditionals of directionality nodes in the correct places, but there might be a better solution.
Ideas
A nice feature would be to implement unicode bidi algorithm in pure Lua, so that short LR text inside RL paragraph won't need a macro use each time (it will also solve the counters problem). I think that
Babel
is doing that whenluatex
is used, but the code is a bit entangled and I found it hard to extract the implementation. There is also this repository but it is outdated and not functional asluatex
has changed allot.More directions could be considered, for cjk and Mongolian for example.
Beta Was this translation helpful? Give feedback.
All reactions