GeneralRight aligning a list in right-to-left languages

LaTeX specific issues not fitting into one of the other forums of this category.
Whazupp
Posts: 9
Joined: Mon Nov 24, 2008 10:04 am

Right aligning a list in right-to-left languages

Post by Whazupp »

Hey there,

I'm trying to make a regular bulleted list (with "enumerate"), that suits right-to-left languages such as hebrew. I'm a new latex user, and I haven't figured out how to do it.

I'd like it to be a mirror image of a normal list. This means that the item tokens are furthest to the right, and that the text is flushed right. I linked an image of what it's supposed to look like.

Maybe theres a truly simple and elegant solution, but it has eluded me?

I'm using the package cjhebrew to write hebrew (if this matters).
Attachments
Image of the right-to-left list
Image of the right-to-left list
right_to_left_list.PNG (1.95 KiB) Viewed 5986 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Whazupp
Posts: 9
Joined: Mon Nov 24, 2008 10:04 am

Re: Right aligning a list in right-to-left languages

Post by Whazupp »

Does anybody have any idea?
Whazupp
Posts: 9
Joined: Mon Nov 24, 2008 10:04 am

Re: Right aligning a list in right-to-left languages

Post by Whazupp »

I'm able to easily produce reversed text using the package cjhebrew. However, i'm not able to float the list to the right, nor put the list bullets on the right.

Perhaps it is possible to modify the enumerate environment?
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Right aligning a list in right-to-left languages

Post by Juanjo »

It is very difficult (at least for me) to adapt the list environment and friends iin order to use them with RL languages. The following code is just an attempt to provide some environments that may work in simple cases:

Code: Select all

\documentclass[a4paper]{article}
\usepackage{cjhebrew}
\usepackage{lipsum}

\newcommand{\RItem}{\vspace{\itemsep}\par\hspace{-\leftmargin}%
   \makebox[\labelwidth][r]{\RLabel}\hspace{\labelsep}}

\newenvironment{RItemize}%
   {\setlength{\rightskip}{\leftmargin}%
    \setlength{\leftskip}{0pt}%
    \setlength{\parindent}{0pt}%
    \setlength{\parskip}{\parsep}%
    \newcommand{\RLabel}{$\bullet$}%
    \vspace{\dimexpr\topsep-\itemsep}%
    \begin{cjhebrew}}%
   {\end{cjhebrew}\vspace{\topsep}\par}
   
\newenvironment{REnumerate}%
   {\setlength{\rightskip}{\leftmargin}%
    \setlength{\leftskip}{0pt}%
    \setlength{\parindent}{0pt}%
    \setlength{\parskip}{\parsep}%
    \setcounter{enumi}{0}%
    \newcommand{\RLabel}{\refstepcounter{enumi}\normalfont\theenumi.}%
    \vspace{\dimexpr\topsep-\itemsep}%
    \begin{cjhebrew}}%
   {\end{cjhebrew}\vspace{\topsep}\par}

\begin{document}

\begin{cjhebrew}
  \lipsum[1]
\end{cjhebrew}

\begin{RItemize}
  \RItem \lipsum[2]
  \RItem \lipsum[3-4]
  \RItem \lipsum[5]
\end{RItemize}

\begin{cjhebrew}
  \lipsum[1]
\end{cjhebrew}

\begin{REnumerate}
  \RItem \lipsum[2]
  \RItem \lipsum[3-4]
  \RItem \lipsum[5]
\end{REnumerate}

\end{document}
The \lipsum command provides meaningless Latin text, which, inside cjhebrew, yields meaningless Hebrew text (I hope so!), just for testing purposes. I attach the pdf file that the above code yields.

EDITED: After writing the above code, I've been aware that the hebrew option of the babel package takes care of this kind of things. This option redefines many commands and environments to adapt them to Hebrew and other right-to-left languages.
Attachments
pru.pdf
(17.86 KiB) Downloaded 233 times
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
Whazupp
Posts: 9
Joined: Mon Nov 24, 2008 10:04 am

Right aligning a list in right-to-left languages

Post by Whazupp »

Awesome! Thanks Juanjo! :) It works perfectly. This case has been solved.

For other people reading this in the future:

When using cjhebrew, if you want to insert "regular" latin text into the items in the list you can use the following code:

Code: Select all

\cjLR{
  \begin{normalfont}
  I'm a piece of regular text
  \end{normalfont}
}
It uses the cjhebrew command cjRL to make right-to-left text, and then changes the font to normal.
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Right aligning a list in right-to-left languages

Post by Juanjo »

... or even simpler

Code: Select all

\cjLR{\normalfont I'm a piece of regular text}
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
Whazupp
Posts: 9
Joined: Mon Nov 24, 2008 10:04 am

Right aligning a list in right-to-left languages

Post by Whazupp »

I found a small bug in the code. The numbered list reverses numbers such as 123 to 312. I found a fix though:

RLabel should be defined as

Code: Select all

\newcommand{\RLabel}{\refstepcounter{enumi}\cjLR{\normalfont\theenumi}}%
The cjhebrew command \cjLR reverses the number.

Also i noticed another problem with the numbered list that I wasn't able to solve. If an item on the list exactly fills an entire line, (without any text being put on the next line), then it creates extra space between the items, As shown in the picture below between lines 2 and 3:
Attachments
Filled line causes extra space between items
Filled line causes extra space between items
arameic_linespacing.PNG (26.09 KiB) Viewed 5853 times
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Re: Right aligning a list in right-to-left languages

Post by Juanjo »

Could you post a minimal working example producing the output shown in the picture? I would like to compile and experiment a bit to try to solve the issue.
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
Whazupp
Posts: 9
Joined: Mon Nov 24, 2008 10:04 am

Right aligning a list in right-to-left languages

Post by Whazupp »

Here's some reduced code with output. The extra space is visible between lines 1 and 2.

Code: Select all

\documentclass[12pt, titlepage]{article}
\usepackage{cjhebrew}


\newcommand{\RItem}{\vspace{\itemsep}\par\hspace{-\leftmargin}%
   \makebox[\labelwidth][r]{\RLabel}\hspace{\labelsep}}
 
\newenvironment{REnumerate}%
   {\setlength{\rightskip}{\leftmargin}%
    \setlength{\leftskip}{0pt}%
    \setlength{\parindent}{0pt}%
    \setlength{\parskip}{\parsep}%
    \setcounter{enumi}{0}%
    \newcommand{\RLabel}{\refstepcounter{enumi}\cjLR{\normalfont\theenumi}}%
    \vspace{\dimexpr\topsep-\itemsep}%
    \begin{cjhebrew}}%
   {\end{cjhebrew}\vspace{\topsep}\par}
   
\begin{document}
\begin{REnumerate}
  \RItem m m m m m m m m m m m m m m m m m m m m m m m m m m m m m mmmmmmmmm
  \RItem m m m m m m m m m m m m m m m m m m m m m m m m
  \RItem m m m m m m m m m m m m m m m m m m m m m m m m m m m m m m m m m m m m m m m m m m m m m m m
\end{REnumerate}
\end{document}
Attachments
Extra space between lines 1 and 2
Extra space between lines 1 and 2
arameic_linespacing2.PNG (3.96 KiB) Viewed 5840 times
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Right aligning a list in right-to-left languages

Post by Juanjo »

There was a small mistake in the definition of \RItem. Use this:

Code: Select all

\newcommand{\RItem}{\par\vspace{\itemsep}\hspace{-\leftmargin}%
   \makebox[\labelwidth][r]{\RLabel}\hspace{\labelsep}}
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
Post Reply