0

I am using package listingsutf8 to have a highlighted python code in my tex output. Try this code -

\documentclass{standalone}
%\usepackage{fontspec} % Currently commented as making no change in the output.
%\setmainfont{Sanskrit2003} % Use any Devanagari font here.
\usepackage{listingsutf8}

\begin{document}
    \begin{lstlisting}
        अ=( "अ","आ","इ","ई","उ","ए","ऐ","ओ","औ")
    \end{lstlisting}
\end{document}

Even if you use listings result doesn't change. I've tried adding a font which has these characters with package fontspec. Still not getting the characters. What should I do?


I tried the solution provided by Ulrike Fischer. This is the new code.

\documentclass{article}
\usepackage{listings,fontspec}
\setmainfont[Script=Devanagari]{Yashomudra}
\makeatletter
\lst@InputCatcodes
\def\lst@DefEC{%
    \lst@CCECUse \lst@ProcessLetter
    ^^^^0905^^^^0906^^^^0907^^^^0908^^^^0909^^^^090a^^^^090b^^^^090c^^^^090d^^^^090e^^^^090f^^^^0911^^^^0912^^^^0913^^^^0914^^^^0915^^^^0916^^^^0917^^^^0918^^^^0919^^^^0920^^^^0921^^^^0922^^^^0923^^^^0924^^^^0925^^^^0926^^^^0927^^^^0928^^^^0929^^^^0930^^^^0931^^^^0932^^^^0933^^^^0934^^^^0935^^^^0936^^^^0937^^^^0938^^^^0939^^^^091a^^^^091b^^^^091c^^^^091d^^^^091e^^^^091f^^^^092a^^^^092b^^^^092c^^^^092d^^^^092e^^^^092f^^^^093e^^^^093f^^^^0940^^^^0941^^^^0942^^^^0943^^^^0944^^^^0945^^^^0946^^^^0947^^^^0948^^^^0949^^^^094b^^^^094d^^^^094c^^00}
\lst@RestoreCatcodes
\makeatother

\begin{document}
    \begin{lstlisting}[extendedchars=true]
        हा देवनागरी लिपीतील मजकूर आहे
        परंतु ह्यात स्वरांशचिन्हे योग्यरूपात दिसत नाहीत.
    \end{lstlisting}
    हा देवनागरी लिपीतील मजकूर आहे\\
    ह्यात स्वरांशचिन्हे योग्यरूपात दिसत आहेत.
\end{document}

Now my output looks like this -

1

How to solve this?

Niranjan
  • 3,435
  • listingsutf8 is unsuitable for the unicode engines. See here https://tex.stackexchange.com/questions/25391/the-listings-package-and-utf-8/25396#25396 – Ulrike Fischer Sep 19 '19 at 12:11
  • I just saw the code that you have provided there, but I want this for a different script. Can you explain what that code means (I mean the stuff inside makeatletter and makeatother) so that I can replace it with the characters that I want? – Niranjan Sep 19 '19 at 12:16
  • Also what if I just want to use listings and also these characters to be processed? Can it be done? Because I must use Xe or Lua. There are other reasons for it. – Niranjan Sep 19 '19 at 12:19
  • simply add your numbers. E.g. औ is U+0914, so you should add ^^^^0914 behind the ^^^^0152. – Ulrike Fischer Sep 19 '19 at 12:23
  • Please see the edit. – Niranjan Sep 19 '19 at 13:29

1 Answers1

1

listings handles the input one by one. It is doesn't work well with scripts like your which do lots of ligatures. You can improve the output with columns=fullflexible but this isn't perfect either. The best result can be get with minted:

\documentclass{article}
\usepackage{listings,fontspec}
\setmainfont[Script=Devanagari]{Noto Sans Devanagari}
\setmonofont[Script=Devanagari]{Noto Sans Devanagari}
\makeatletter
\lst@InputCatcodes
\def\lst@DefEC{%
    \lst@CCECUse \lst@ProcessLetter
    ^^^^0905^^^^0906^^^^0907^^^^0908^^^^0909^^^^090a^^^^090b^^^^090c^^^^090d^^^^090e^^^^090f^^^^0911^^^^0912^^^^0913^^^^0914^^^^0915^^^^0916^^^^0917^^^^0918^^^^0919^^^^0920^^^^0921^^^^0922^^^^0923^^^^0924^^^^0925^^^^0926^^^^0927^^^^0928^^^^0929^^^^0930^^^^0931^^^^0932^^^^0933^^^^0934^^^^0935^^^^0936^^^^0937^^^^0938^^^^0939^^^^091a^^^^091b^^^^091c^^^^091d^^^^091e^^^^091f^^^^092a^^^^092b^^^^092c^^^^092d^^^^092e^^^^092f^^^^093e^^^^093f^^^^0940^^^^0941^^^^0942^^^^0943^^^^0944^^^^0945^^^^0946^^^^0947^^^^0948^^^^0949^^^^094b^^^^094d^^^^094c^^00}
\lst@RestoreCatcodes
\makeatother
\usepackage{minted}
\begin{document}
\begin{lstlisting}[extendedchars=true,columns=fullflexible]
        हा देवनागरी लिपीतील मजकूर आहे
        परंतु ह्यात स्वरांशचिन्हे योग्यरूपात दिसत नाहीत.
\end{lstlisting}


\begin{minted}{latex}
        हा देवनागरी लिपीतील मजकूर आहे
        परंतु ह्यात स्वरांशचिन्हे योग्यरूपात दिसत नाहीत.
\end{minted}

    हा देवनागरी लिपीतील मजकूर आहे\\
    ह्यात स्वरांशचिन्हे योग्यरूपात दिसत आहेत.
\end{document}

Output of xelatex --shell-escape file

enter image description here

Ulrike Fischer
  • 327,261