0

I am trying to write a bilingual (Bangla+English) document using LaTeXbangla package.

Here's my MWE:

\documentclass{article}
\usepackage[banglamainfont=Kalpurush, 
            banglattfont=Siyam Rupali]{latexbangla}
\begin{document}
পিথাগোরাস(Pythagoras)-এর উপপাদ্যটি হল,\\
\textit{সমকোণী ত্রিভুজের অতিভুজের উপর অঙ্কিত  
বর্গক্ষেত্রের ক্ষেত্রফল অপর দুই বাহুর উপর অঙ্কিত বর্গক্ষেত্রের ক্ষেত্রফলের সমষ্টির সমান।} \\
অর্থাৎ কোন সমকোণী ত্রিভুজের অতিভুজ $c$ এবং অপর দুই বাহু $a$ এবং $b$ হলে,
\[c^2=a^2+b^2\]
লক্ষ্য করুন, এখন পর্যন্ত টেক্সট প্রদর্শনের জন্য \textbf{কালপুরুষ} ফন্ট ব্যবহৃত হয়েছে।\\
\texttt{এবার, টেলিটাইপ(Teletype) টেক্সট প্রদর্শনের জন্য \textbf{সিয়াম রূপালী} ফন্ট ব্যবহৃত হল।}\\
পুনরায় টেক্সট প্রদর্শনের জন্য \textbf{কালপুরুষ  ফন্ট ব্যবহৃত  হচ্ছে।}
\end{document}

When I compile it with Miktex XeLaTeX (Windows 10), it's giving me the output perfectly. But with Overleaf XeLaTeX, it's not working. Why is it happening? How can I fix this issue?

raf
  • 633
  • What errors are you getting? Does changing the engine to TeX Live 2020 work? – Davislor Dec 20 '20 at 22:27
  • @Davislor I just tried it it times out, I guess the font isn't there and it's re-running fc-cache but as it times out you don't get any usable message. – David Carlisle Dec 20 '20 at 23:07
  • @raf if the fonts you are using are freely available you can upload them to your project otherwise you need to pick a font that is available to the linux texlive being used by overleaf. – David Carlisle Dec 20 '20 at 23:08
  • @DavidCarlisle Good instincts! When I press the “Show raw logs” button, it does give the font-not-found messages. – Davislor Dec 20 '20 at 23:30

2 Answers2

1

The problem (as David Carlisle correctly intuited) is that Overleaf does not have those fonts installed. If you click the “Show raw logs” button, you will see the error message.

Thanks to @imnothere for linking the list of Bengali fonts available in Overleaf. You should be able to substitute any of these. Some will need the AutoFakeBold = or AutoFakeSlant = options.

As David Carlisle suggested in a comment, if the font you want to use is free, you can put a copy of the font file in your project folder.

A Solution

Downloading the font files to your project folder was not enough to get latexbangla to work. (It might be possible to hack a fix with \defaultfontfeatures.) What I ended up doing instead was write a new solution that uses babel in LuaLaTeX from 2020 or later.

Since you use both bold and italic, but the fonts you linked me to come with neither, I had fontspec fake both bold and slanted.

First, create a new sub-folder named fonts and upload both kalpurush.ttf and Siyamrupah.ttf to it. The following MWE now works for me:

\documentclass{article}
\tracinglostchars=2
\usepackage[bidi=basic,
            layout=sectioning.tabular,
            nil
           ]{babel}
\usepackage{unicode-math}

\defaultfontfeatures{ Scale=MatchLowercase, Ligatures=TeX, Renderer=HarfBuzz }

%% Kalpurush and Siyam Rupali are free for %% download at: %% https://www.omicronlab.com/bangla-fonts.html \defaultfontfeatures[kalpurush]{ Path = ./fonts/ , Extension = .ttf , AutoFakeBold = 1.2 , AutoFakeSlant = 0.2 } \defaultfontfeatures[Siyamrupali]{ Path = ./fonts/ , Extension = .ttf , AutoFakeBold = 1.2 , AutoFakeSlant = 0.2 }

\babelprovide[import, onchar=ids fonts]{english} \babelfont{rm} [Language=Default]{NewComputerModernBook} \babelfont{sf} [Language=Default]{NewComputerModernSansBook} \babelfont{tt} [Language=Default]{NewComputerModernMonoBook}

\babelprovide[import=bn, main, onchar=ids fonts ]{bangla} \babelfont[bangla]{rm} {kalpurush} \babelfont[bangla]{sf} {Siyamrupali} \babelfont[bangla]{tt} {Siyamrupali}

\setmathfont{NewCMMath-Book.otf}

\begin{document} পিথাগোরাস(Pythagoras)-এর উপপাদ্যটি হল,\ \textit{সমকোণী ত্রিভুজের অতিভুজের উপর অঙ্কিত
বর্গক্ষেত্রের ক্ষেত্রফল অপর দুই বাহুর উপর অঙ্কিত বর্গক্ষেত্রের ক্ষেত্রফলের সমষ্টির সমান।} \ অর্থাৎ কোন সমকোণী ত্রিভুজের অতিভুজ $c$ এবং অপর দুই বাহু $a$ এবং $b$ হলে, [c^2=a^2+b^2] লক্ষ্য করুন, এখন পর্যন্ত টেক্সট প্রদর্শনের জন্য \textbf{কালপুরুষ} ফন্ট ব্যবহৃত হয়েছে।\ \texttt{এবার, টেলিটাইপ(Teletype) টেক্সট প্রদর্শনের জন্য \textbf{সিয়াম রূপালী} ফন্ট ব্যবহৃত হল।}\ পুনরায় টেক্সট প্রদর্শনের জন্য \textbf{কালপুরুষ ফন্ট ব্যবহৃত হচ্ছে।} \end{document}

I warn you that the fake-bold teletype text has some terrible hinting, which makes it look ugly in this low-res image. It’s not nearly so bad when you see the full-size PDF.

Kalpurush/Siyam Rupali sample

The Siyam rupali font has some trouble displaying English text in parentheses. Switching to Mukti Narrow or Mitra fixed them, or it’s possible to configure babel to automatically switch to the English font whenever it sees ( or ).

The layout will look much better if you remove the \\ breaks and let the LaTeX line-breaking algorithm work. The microtype package (with font protrusion off if you mind the large number of benign warning messages it gives you when you load a Bangla font) might also help.

\documentclass{article}
\tracinglostchars=2
\usepackage[bidi=basic,
            layout=sectioning.tabular,
            nil
           ]{babel}
\usepackage{unicode-math}
\usepackage{microtype}

\defaultfontfeatures{ Scale=MatchLowercase, Ligatures=TeX, Renderer=HarfBuzz }

%% Kalpurush and Siyam Rupali are free for %% download at: %% https://www.omicronlab.com/bangla-fonts.html \defaultfontfeatures[kalpurush]{ % Path = ./fonts/ , Extension = .ttf , AutoFakeBold = 1.2 , AutoFakeSlant = 0.2 } \defaultfontfeatures[Siyamrupali]{ % Path = ./fonts/ , Extension = .ttf , AutoFakeBold = 1.2 , AutoFakeSlant = 0.2 } \defaultfontfeatures[Mitra]{ AutoFakeBold = 1.2 }

\babelprovide[import, onchar=ids fonts]{english} \babelfont{rm} [Language=Default]{NewComputerModernBook} \babelfont{sf} [Language=Default]{NewComputerModernSansBook} \babelfont{tt} [Language=Default]{NewComputerModernMonoBook}

\babelprovide[import=bn, main, onchar=ids fonts ]{bangla} \babelfont[bangla]{rm} {kalpurush} \babelfont[bangla]{sf} {MuktiNarrow} \babelfont[bangla]{tt} {Mitra}

\setmathfont{NewCMMath-Book.otf}

\begin{document} পিথাগোরাস(Pythagoras)-এর উপপাদ্যটি হল, \textit{সমকোণী ত্রিভুজের অতিভুজের উপর অঙ্কিত
বর্গক্ষেত্রের ক্ষেত্রফল অপর দুই বাহুর উপর অঙ্কিত বর্গক্ষেত্রের ক্ষেত্রফলের সমষ্টির সমান।} অর্থাৎ কোন সমকোণী ত্রিভুজের অতিভুজ $c$ এবং অপর দুই বাহু $a$ এবং $b$ হলে,

[c^2=a^2+b^2]

লক্ষ্য করুন, এখন পর্যন্ত টেক্সট প্রদর্শনের জন্য \textbf{কালপুরুষ, ফন্ট ব্যবহৃত হয়েছে।} \texttt{এবার, টেলিটাইপ (Teletype)টেক্সট প্রদর্শনের জন্য \textbf{সিয়াম রূপালী} ফন্ট ব্যবহৃত হল।} পুনরায় টেক্সট প্রদর্শনের জন্য \textbf{কালপুরুষ ফন্ট ব্যবহৃত হচ্ছে।} \end{document}

Kalpurush/Mitra sample

And a solution using only fonts installed on Overleaf:

\documentclass{article}
\tracinglostchars=2
\usepackage[bidi=basic,
            layout=sectioning.tabular,
            nil
           ]{babel}
\usepackage{unicode-math}

\defaultfontfeatures{ Scale=MatchLowercase, Ligatures=TeX, Renderer=HarfBuzz }

\babelprovide[import, onchar=ids fonts]{english} \babelfont{rm} [Language=Default]{NewComputerModernBook} \babelfont{sf} [Language=Default]{NewComputerModernSansBook} \babelfont{tt} [Language=Default]{NewComputerModernMonoBook}

\defaultfontfeatures[LohitBengali]{ AutoFakeBold = 1.2, AutoFakeSlant = 0.175 } \defaultfontfeatures[MitraMono]{ AutoFakeBold = 1.2 }

\babelprovide[import=bn, main, onchar=ids fonts ]{bangla} \babelfont[bangla]{rm} [Language=Default]{LohitBengali} \babelfont[bangla]{sf} [Language=Default]{MuktiNarrow} \babelfont[bangla]{tt} [Language=Default, Scale=0.75]{MitraMono}

\setmathfont{NewCMMath-Book.otf}

\begin{document} পিথাগোরাস(Pythagoras)-এর উপপাদ্যটি হল, \textit{সমকোণী ত্রিভুজের অতিভুজের উপর অঙ্কিত
বর্গক্ষেত্রের ক্ষেত্রফল অপর দুই বাহুর উপর অঙ্কিত বর্গক্ষেত্রের ক্ষেত্রফলের সমষ্টির সমান।} অর্থাৎ কোন সমকোণী ত্রিভুজের অতিভুজ $c$ এবং অপর দুই বাহু $a$ এবং $b$ হলে,

[c^2=a^2+b^2]

লক্ষ্য করুন, এখন পর্যন্ত টেক্সট প্রদর্শনের জন্য \textbf{কালপুরুষ} ফন্ট ব্যবহৃত হয়েছে। \texttt{এবার, টেলিটাইপ (Teletype) টেক্সট প্রদর্শনের জন্য \textbf{সিয়াম রূপালী} ফন্ট ব্যবহৃত হল।} পুনরায় টেক্সট প্রদর্শনের জন্য \textbf{কালপুরুষ ফন্ট ব্যবহৃত হচ্ছে।} \end{document}

Davislor
  • 44,045
  • Thank you. But the FreeSerif, FreeSans don't display the words properly. The fonts (TTF files of Kalpurush and Siyam Rupali) that I want to use are available online here: https://www.omicronlab.com/bangla-fonts.html Can you kindly show me how to use the uploaded font files with latexbangla in overleaf? – raf Dec 21 '20 at 03:29
  • 1
    @raf I’ve posted an updated solution that at least finds the correct fonts on Overleaf, although I think the text got garbled somewhere along the way. It does not use the exact same packages as your original MWE, so I’m not sure whether it will meet your needs. (For example, latexbangla provides certain theorem environments that you would need to define yourself. And it runs in LuaLaTeX, not XeLaTeX.) I did get it to compile your MWE. – Davislor Dec 21 '20 at 04:40
  • 1
    @raf I had some trouble displaying English inside parentheses with Siyam Rupali; this seems to be a problem with the font, and switching fonts fixed it. It would also be possible to tell Babel to always display ( and ) from the English font. The layout seems to be much better if I remove the \\ breaks and allow the line-breaking algorithm to do its work. Babel has hyphenation patterns, and microtype also helps. – Davislor Dec 21 '20 at 05:22
  • 1
    List of fonts for Bangla/Bengali: https://www.overleaf.com/learn/latex/Questions/Which_OTF_or_TTF_fonts_are_supported_via_fontspec%3F#Bengali – imnothere Dec 21 '20 at 05:49
  • 1
    @imnothere Thank you! That’s very useful. – Davislor Dec 21 '20 at 05:53
  • Thank you so much, @Davislor. Another problem I am facing while writing/typing Bangla in Overleaf editor in Google Chrome. The same issue for Firefox is discussed here: https://support.mozilla.org/bg/questions/1263396 – raf Dec 21 '20 at 11:46
  • 1
    @raf I noticed what I think is the same issue. I ended up editing offline and pasting into the Overleaf window. – Davislor Dec 21 '20 at 18:24
  • @Davislor, I contacted the Overleaf support team about this cursor offset issue. They suggested trying the rich text editor. But it didn't work for me. So same as you, I ended up using my offline LaTeX editors for Bangla writing purposes. – raf Dec 24 '20 at 19:53
0

Today, I have found that the font 'Kalpurush' is added to the list of Overleaf-supported Bengali fonts. The following MWE is perfectly compiled with Overleaf XeLaTeX (Texlive 2022):

\documentclass{article}

% latexbangla with all features \usepackage[banglamainfont=Kalpurush, banglattfont=Kalpurush ]{latexbangla}
% activate polyglossia \setdefaultlanguage[numerals=Bengali, changecounternumbering=true ]{bengali} \setotherlanguage{english}

\begin{document} পিথাগোরাস (Pythagoras)-এর উপপাদ্যটি হল,\ \textit{সমকোণী ত্রিভুজের অতিভুজের উপর অঙ্কিত বর্গক্ষেত্রের ক্ষেত্রফল অপর দুই বাহুর উপর অঙ্কিত বর্গক্ষেত্রের ক্ষেত্রফলের সমষ্টির সমান।} \ অর্থাৎ কোন সমকোণী ত্রিভুজের অতিভুজ $c$ এবং অপর দুই বাহু $a$ এবং $b$ হলে, [c^2=a^2+b^2] \end{document}

Till now (September 7, 2022), the font Siam Rupali is not supported/available in Overleaf. Also, I don't feel the need to use a separate teletype font in Bangla texts. So, I have set the same font in both options of latexbangla package in the above MWE.

raf
  • 633