Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

So I've been trying to get satisfactory results typesetting Persian and Arabic poems, in the traditional format, with XeLaTeX. It works just about fine – see the sample document below – but I would like to get line numbers. I want the formatting to look something like this example, a different poem that I put together using an Adobe product that shall remain unnamed.

Can anyone think of a way of getting line numbers while using these packages? (bidipoem & XePersian) Thanks!

%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode
\documentclass[12pt,letterpaper]{article}
\usepackage{xltxtra}
\usepackage{fullpage}
\usepackage{hyperref}
\usepackage{setspace}
\usepackage{bidipoem}
\usepackage[Kashida]{xepersian}
\settextfont[Scale=1.4]{Scheherazade}
\setlatintextfont[Ligatures=TeX]{Brill}
\renewcommand{\thepage}{\texorpdfstring{\lr{\arabic{page}}}{\arabic{page}}}
\begin{document}
\begin{latin}
\title{Typesetting sample: \emph{Ghazal no.\ 1} of Ḥāfeẓ}
\author{}
\date{}
\maketitle
\section*{Persian text}
\end{latin}
\vspace{-4.5pc}
\begin{spacing}{1.5}
\begin{traditionalpoem}
\\الا یا ایّها الساقی ادر کأسا و ناولها&که عشق آسان نمود اول ولی افتاد مشکلها
\\به بوی نافه‌ای کآخر صبا زان طره بگشاید&ز تاب جعد مشکینش چه خون افتاد در دلها
\\مرا در منزل جانان چه امن عیش چون هر دم&جرس فریاد می‌دارد که بربندید محملها
\\به می سجاده رنگین کن گرت پیر مغان گوید&که سالک بی‌خبر نبْوَد ز راه و رسم منزلها
\\شب تاریک و بیم موج و گردابی چنین هایل&کجا دانند حال ما سبکباران ساحلها
\\همه کارم ز خود کامی به بدنامی کشید آخر&نهان کی ماند آن رازی کز او سازند محفلها
\\حضوری گر همی‌خواهی از او غایب مشو حافظ
\\متی ما تلق من تهوی دع الدنیا و اهملها
\end{traditionalpoem}
\end{spacing}
\end{document}
share|improve this question
    
I found this but I couldn't manage to make it work. Might help tug.org/pipermail/xetex/2010-October/018797.html –  interlude Jun 28 '12 at 7:41
    
Yeah, I went over that thread and fiddled around with the options they were discussing, but none of it worked for me. Ah well! –  TSB Jun 28 '12 at 16:48
add comment

2 Answers

up vote 2 down vote accepted

Solution for XeTeX

I've done it! (I hope) Result is: ghazal in xetex

Hope this works.

%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode
\documentclass[12pt,letterpaper]{article}
\usepackage{xltxtra}
\usepackage{fullpage}
\usepackage{hyperref}
\usepackage{setspace}
\usepackage{bidipoem}
\usepackage[Kashida]{xepersian}
\settextfont[Scale=1.4]{Scheherazade}
\setlatintextfont[Ligatures=TeX]{Brill}


\newcount\LineNumber \newcount\templinenumber
 \newdimen\linenumberskip \linenumberskip=-1em
 \chardef\linestep=3
\def\poemlinenumber{%
    \advance\LineNumber1
    \templinenumber=\LineNumber
   \computelinenumber
   }
 \def\computelinenumber{%
    \ifnum\templinenumber>\linestep
      \advance\templinenumber-\linestep
      \expandafter\computelinenumber
    \else
     \ifnum\templinenumber=\linestep
       \leavevmode\rlap{\kern\linenumberskip\the\LineNumber}%
      \fi
    \fi
   }
 \newenvironment{numberedpoem}
   {\everypar{\everypar{\poemlinenumber}}%
     \begin{traditionalpoem}}
    {\end{traditionalpoem}}

\renewcommand{\thepage}{\texorpdfstring{\lr{\arabic{page}}}{\arabic{page}}}
\begin{document}
\begin{latin}
\title{Typesetting sample: \emph{Ghazal no.\ 1} of Ḥāfeẓ}
\author{}
\date{}
\maketitle
\section*{Persian text}
\end{latin}
\vspace{-4.5pc}
\begin{spacing}{1.5}
\begin{numberedpoem}
\\الا یا ایّها الساقی ادر کأسا و ناولها&که عشق آسان نمود اول ولی افتاد مشکلها
\\به بوی نافه‌ای کآخر صبا زان طره بگشاید&ز تاب جعد مشکینش چه خون افتاد در دلها
\\مرا در منزل جانان چه امن عیش چون هر دم&جرس فریاد می‌دارد که بربندید محملها
\\به می سجاده رنگین کن گرت پیر مغان گوید&که سالک بی‌خبر نبْوَد ز راه و رسم منزلها
\\شب تاریک و بیم موج و گردابی چنین هایل&کجا دانند حال ما سبکباران ساحلها
\\همه کارم ز خود کامی به بدنامی کشید آخر&نهان کی ماند آن رازی کز او سازند محفلها
\\حضوری گر همی‌خواهی از او غایب مشو حافظ
\\متی ما تلق من تهوی دع الدنیا و اهملها
\end{numberedpoem}
\end{spacing}
\end{document}

My code does not have much flexibility but might help you. I'm not sure if line numbers are correct. If it is not delete \\ at the first line and add vspace


Solution for pdflatex

Use ledarab package and \arablnumrep command.

I don't know Arabic but this look like correct:ghazal with arabic numbers

%!TEX TS-program = pdflatex
%!TEX encoding = UTF-8 Unicode
\documentclass[11pt,letterpaper]{scrartcl}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{fullpage}
\usepackage{arabtex}
\usepackage{verses}
\usepackage{ledmac}

\usepackage{ledarab}

\setstanzaindents{0,0,0}
\lineation{section}
\setcounter{firstlinenum}{3}
\setcounter{linenumincrement}{3}

\setkomafont{disposition}{\rmfamily\mdseries}

\arablnumrep
\begin{document}

\title{Another \d H\=afe\d z \emph{ghazal} example}
\author{}
\date{}
\maketitle

\vspace{-4pc}

\section*{\emph{Ghazal} no.~1}

\beginnumbering
\linenummargin{right}
\pstart
\begin{arabtext} \setfarsi \transfalse \arabtrue \novocalize

\setversedim{70mm}{8mm}

\halfverses{'alA yA ayyuhA as-sAqI 'adir" ka's"aN wa nAwil"hA}{kiH `i^sq AsAn numUd awwal walI uftAd mu^skilhA}
\halfverses{baH bU-ye nAfaH"|I k'A_hir .sabA zAn .turraH bag^sAyad}{zi tAb"e zulf"e mu^skIna^s ^ciH _hUn uftAd dar dilhA}
\halfverses{baH may sajjAdaH rangIn kun garat pIr"e mu.gAn gUyad}{kiH sAlik bI_habar nab"w"ad zi rAH wa rasm"e manzilhA}
\halfverses{marA dar manzil"e jAnAn ^ciH amn"e `ay^s ^cUn har dam}{jaras faryAd mI"|dArad kiH bar bandId ma.hmilhA}
\halfverses{^sab"e tArIk wa bIm"e mawj wa girdAbI ^cunIn hA'il}{kujA dAnand .hAl"e mA sabukbArAn"e sA.hilhA}
\halfverses{hamaH kAram zi _hUdkAmI baH badnAmI ka^sId ArI}{nihAn kay mAnad An rAzI kaz An sAzand ma.hfilhA}
\halfverses{.hu.dUrI gar hamI _hwAhI azU .gA'ib ma^saw .hAfi.z}{matY mA talq"a man tahwY da`"a ad-dunyA wa 'ahmil"hA}

\end{arabtext}  \transtrue \arabfalse
\pend
\endnumbering

\end{document}
share|improve this answer
    
This is the best I've seen yet. Everything except the font works quite well. Thanks for doing this! –  TSB Jun 29 '12 at 16:43
    
I've also gone ahead and accepted this answer, at least for the time being. I would love to be able to get line numbers using the bidipoem package and a nice font in XeLaTeX, but I haven't seen any indication that that's possible. –  TSB Jun 29 '12 at 16:48
    
@TSB I've extended my answer –  interlude Jun 29 '12 at 21:23
add comment

edit: interlude has taken this code and improved upon it considerably in an answer above.

Alright, I may as well post one other option that I've been exploring, vith very limited success. This runs through pdflatex, and it relies on the arabtex, ledmac and verses packages. The code below is based on a document that I got from a friend of a friend. I don't think I would ever have come up with this on my own, and it still has some problems.

  1. The line numbers come out in Latin script, and I can't think how I might go about changing that.
  2. The Persian/Arabic font used by arabtex is really bad. I wish I had something nice to say about it, but compared to using e.g. SIL Scheherazade with XeTeX, it's not even in the same ballpark.

Anyway, maybe this will at least inspire ideas from more experienced TeX users.

%!TEX TS-program = pdflatex
%!TEX encoding = UTF-8 Unicode
\documentclass[11pt,letterpaper]{scrartcl}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{fullpage}
\usepackage{arabtex}
\usepackage{verses}
\usepackage{ledmac}

\setstanzaindents{0,0,0}
\lineation{section}
\setcounter{firstlinenum}{3}
\setcounter{linenumincrement}{3}

\setkomafont{disposition}{\rmfamily\mdseries}

\begin{document}

\title{Another \d H\=afe\d z \emph{ghazal} example}
\author{}
\date{}
\maketitle

\vspace{-4pc}

\section*{\emph{Ghazal} no.~1}

\beginnumbering
\linenummargin{right}
\pstart
\begin{arabtext} \setfarsi \transfalse \arabtrue \novocalize

\setversedim{70mm}{8mm}

\halfverses{'alA yA ayyuhA as-sAqI 'adir" ka's"aN wa nAwil"hA}{kiH `i^sq AsAn numUd awwal walI uftAd mu^skilhA}
\halfverses{baH bU-ye nAfaH"|I k'A_hir .sabA zAn .turraH bag^sAyad}{zi tAb"e zulf"e mu^skIna^s ^ciH _hUn uftAd dar dilhA}
\halfverses{baH may sajjAdaH rangIn kun garat pIr"e mu.gAn gUyad}{kiH sAlik bI_habar nab"w"ad zi rAH wa rasm"e manzilhA}
\halfverses{marA dar manzil"e jAnAn ^ciH amn"e `ay^s ^cUn har dam}{jaras faryAd mI"|dArad kiH bar bandId ma.hmilhA}
\halfverses{^sab"e tArIk wa bIm"e mawj wa girdAbI ^cunIn hA'il}{kujA dAnand .hAl"e mA sabukbArAn"e sA.hilhA}
\halfverses{hamaH kAram zi _hUdkAmI baH badnAmI ka^sId ArI}{nihAn kay mAnad An rAzI kaz An sAzand ma.hfilhA}
\halfverses{.hu.dUrI gar hamI _hwAhI azU .gA'ib ma^saw .hAfi.z}{matY mA talq"a man tahwY da`"a ad-dunyA wa 'ahmil"hA}

\end{arabtext}  \transtrue \arabfalse
\pend
\endnumbering

\end{document}
share|improve this answer
    
You should add this to your question because it is not an answer. –  interlude Jun 29 '12 at 14:02
    
I appreciate your concern for protocol, but I don't agree that this is just a part of my question. It's a different approach that solves one of the original issues, albeit partially. Anyway, I think this should be left where it is, even though the answer you've posted is quite a bit better. –  TSB Jun 29 '12 at 16:41
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.