2

I wonder what is the best way for parallel typesetting of some Sanskrit strings in Devanāgarī and transliteration. Presently I could imagine doing it with a table, as in this example:

\documentclass{memoir}
\usepackage{polyglossia}
\usepackage{fontspec}
\setdefaultlanguage{english}
\setotherlanguage{sanskrit}
\newfontfamily\sanskritfont[Script=Devanagari,Mapping=RomDev,
Scale=2.2,
]{Sanskrit 2003}
\setlength{\tabcolsep}{0pt}

\begin{document}
\begin{tabular}{cccccccccc}
\textsanskrit{a}&\textsanskrit{tha}&\hspace{0.5cm} &\textsanskrit{yo}&\textsanskrit{gā}&\textsanskrit{nu}&\textsanskrit{śā}&\textsanskrit{sa}&\textsanskrit{na}&\textsanskrit{m} \\
a&tha& &yo&gā&nu&śā&sa&na&m \\
\end{tabular}
\end{document}

sample table

I am not that happy with that yet, as there appear to be small gaps between the syllables in some places, the spaces between words don't work automatically and of course it involves quite a bit of manual work to set up such a table.

I could imagine a command with a transliterated Sanskrit string as its one argument, that then

  1. Splits up the string into the syllables,
  2. Counts these,
  3. Sets up a table accordingly, possibly dealing with line and page breaks for longer strings.

But this might not be the best way. Is there any other, better way of horizontally aligning texts other than a table?

Syllables in the Indic context are normally a combination of a consonant (cluster) with an attached vowel (or dipthong), possibly a modifier (Visarga, Anusvāra, Candrabindu etc.). The two exceptions to this would be 1) Independent vowels at the beginning of a word, and 2) words ending in consonant. (Well, in Devanāgarī one would normally join a word starting with a vowel with the preceding word ending on with a consonant, but in transliteration one would not do so.) hyph-sa.tex kind of has all of that already.

If one does this via a table, then maybe LaTeX might not be the best tool to generate the table code, it might be easier to generate it externally, for example using a perl script.

1

Not a perfect solution, but just to get you started (and to help others understand the question):

After installing the font Sanskrit2003 from here and Romdev.tec per here, can try the following:

\documentclass{memoir}
\usepackage{polyglossia}
\usepackage{fontspec}
\setdefaultlanguage{english}
\setotherlanguage{sanskrit}
\newfontfamily\sanskritfont[Script=Devanagari,Mapping=RomDev,Scale=2.2]{Sanskrit 2003}

% \def\s#1{\vtop{\hbox{\textsanskrit{#1}}\hbox{\hss#1\hss}}}
\newbox\boxA
\def\s#1{%
  \leavevmode%
  \setbox\boxA\hbox{\textsanskrit{#1}}%
  \vtop{\copy\boxA\hbox to \wd\boxA{\hss#1\hss}}}

\begin{document}

\textsanskrit{atha yogānuśāsanam}  % Just text, for comparison

\s{a}\s{tha} \s{yo}\s{gā}\s{nu}\s{śā}\s{sa}\s{na}\s{m}

\end{document}

How the macro works: for example, \s{yo} first puts यो (the result of \textsanskrit{yo}) into \boxA, then typesets two boxes one over (\vtop) the other: namely \boxA over \hbox to \wd\boxA{\hss yo\hss}. The \hss is a TeX primitive for “horizontal stretch or shrink”, so that the Latin-script “yo” is centered in a box of size that of the Devanagari यो.

output

You can have a bunch of these \s{...}s in a line and lines will break at spaces but not elsewhere.

Of course, typing \s{a}\s{tha} \s{yo}\s{gā}\s{nu}\s{śā}\s{sa}\s{na}\s{m} is not very convenient either, so maybe someone will have something better :-) (Or else you could generate that input from an external program.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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