0

I am trying to configure a bilingual (Bangla+English) quote environment in book class. For the following MWE, I am using these fonts:

  1. Kalpurush (download source)
  2. My Type Of Font (download source)

(The second one can be replaced with any familiar English font.)

test_quote.sty

\RequirePackage[banglamainfont=Kalpurush,   % Kalpurush font: https://www.omicronlab.com/bangla-fonts.html 
                banglattfont=Kalpurush,
               ]{latexbangla}
%activate polyglossia
\setdefaultlanguage[numerals=Bengali,
changecounternumbering=true]{bengali}
%number all levels
% \setcounter{secnumdepth}{5}
%     \setotherlanguage{english}

% new font for quotation
\newfontfamily\quotefont[%
    % Scale= 1.1,
    % WordSpace=1.4,
    % AutoFakeSlant=1.2,
    % AutoFakeBold=1.2
    ]{[mytype]}  % My Type Of Font font: https://www.1001freefonts.com/my-type-of-font.font 

% A chapquote environment for chapter quotes
\newenvironment{chapquote}[2][2em]
{\setlength{\@tempdima}{#1}%
    \def\chapquote@author{#2}%
    \parshape 1 \@tempdima \dimexpr\textwidth-2\@tempdima\relax%
    \uccoff \quotefont 
}
{\par\hfill \uccoff — \uccon \chapquote@author\hspace*{\@tempdima}\par\bigskip}  

test_quote.tex

% !TEX program = xelatex
\documentclass[12pt, oneside]{book}
\usepackage{test_quote}

\begin{document}

আমার পছন্দের একটা উক্তি হলঃ \\

\begin{chapquote}{কার্ল সেগান (Carl Sagan)}
    One glance at a book and you hear the voice of another person, perhaps someone dead for 1000 years. To read is to voyage through time.
\end{chapquote}

\vspace{4em}
এটার বাংলা অনুবাদ করলে দাঁড়ায় এমনঃ \\

\begin{chapquote}{কার্ল সেগান (Carl Sagan)}
    একটি বইয়ের পাতায় এক নজর তাকালে আপনি অন্য ব্যক্তির কণ্ঠ শুনতে পান, সেই ব্যক্তি হয়তো ১০০০ বছর আগে মারা গিয়েছেন। বই-পড়ার মাধ্যমে সময়-ভ্রমণের সুযোগ হয়।
\end{chapquote}

\end{document}

Currently, the Bangla texts are not appearing in the chapquote environment. Also, there's no option to put a quote source. My desired features for the chapquote environment are:

  • Allowing to use of both fonts in the quote-text. Activating the English mytype font only on the texts that are inside the command \quotefont{}. Otherwise, the texts should remain in the default font of the document which was set up in the option of latexbangla.
  • Keeping the quote-author name in the default font
  • Adding an optional argument for showing the quote-source in the next line of quote-author in the default(italic) font. Its alignment should be as same as the quote-author.

Using the above feature, I want to use the environment as something like the following way:

আমার পছন্দের একটা উক্তি হলঃ \\
\begin{chapquote}{কার্ল সেগান (Carl Sagan)}{The source of the quote}              % Quote Source should be optional
    \quotefont{One glance at a book and you hear the voice of another person, perhaps someone dead for 1000 years. To read is to voyage through time.}            
    % The quote texts will be in the quotefont (mytype), but the quote author and source will be in defaut font.
\end{chapquote}
এটার বাংলা অনুবাদ করলে দাঁড়ায় এমনঃ \\
\begin{chapquote}{কার্ল সেগান (Carl Sagan)}
    একটি বইয়ের পাতায় এক নজর তাকালে আপনি অন্য ব্যক্তির কণ্ঠ শুনতে পান, সেই ব্যক্তি হয়তো ১০০০ বছর আগে মারা গিয়েছেন। বই-পড়ার মাধ্যমে সময়-ভ্রমণের সুযোগ হয়।           
     % The quote texts, author and source all will be in defaut font.
\end{chapquote}

My desired output is something like: my desired output

6
  • 1
    Comment out the \uccoff \quotefont in your environment definition "begin code" part to see the effect of latexbangla, as it handles the transitions. What do you want quotefont to do? Latin or Bangla? Or have a quotefontbangla if uccoff??
    – Cicada
    Jun 2, 2021 at 14:58
  • 1
    Perhaps a local settransitions command could work - see ucharclasses documentation for the syntax.
    – Cicada
    Jun 2, 2021 at 15:15
  • I want to use \quotefont{only english text} to change the only english text to the font mytype. Otherwise the default font of latexbangla should be used. And I want to use \quotefont anywhere in my document.
    – raf
    Jun 2, 2021 at 15:18
  • 1
    You'll need {\quotefont only english text} to restrict the scope of the font if you don't want automatic transitions.
    – Cicada
    Jun 2, 2021 at 15:25
  • Using the style file in the question, I am trying to use {\quotefont only english text}. I don't understand why it's not working!
    – raf
    Jun 2, 2021 at 18:14

2 Answers 2

1

latexbangla is using ucharclasses's Unicode block-transitioning mechanism to assign polyglossia language environments, which in turn means the chapquote structure ends up with overlapping environments instead of nested environments because space counts as part of the latin codeblock. And so, the inevitable error message.

A long-term solution is to slightly decouple ucharclasses from the Unicode codeblock definitions by putting space, punctuation and digits into their own (logical) codeblocks.

A short-term workaround is to take over manual control in the chapquote environment and action the ucharclasses and polyglossia functions separately.

Luckily, there are only two languages/script to consider.

chapquote example

Here, to visibly highlight what is going on, the Latin quote font is FreeSerif in violet, and the Bengali quote font is Charu_Chandan_3D_Unicode-Regular in blue.

The chapquote environment is modified to have just font commands in the ucharclasses transition commands, when going into Latin text and leaving it, and when going into Bangla text. No polyglossia environment declarations in the ucharclasses commands.

Instead, \begin{latin} and \end{latin} is manually added around the English quote text.

Outside the chapquote environment, the latexbangla settings have effect as usual.

MWE

% !TEX program = xelatex
\documentclass[12pt, oneside]{book}
\usepackage{xcolor}

%\usepackage{test_quote}
%vvvvv
\makeatletter
\RequirePackage[banglamainfont=Kalpurush,   % Kalpurush font: https://www.omicronlab.com/bangla-fonts.html 
                banglattfont=Kalpurush,
               ]{latexbangla}
%activate polyglossia
\setdefaultlanguage[numerals=Bengali,
changecounternumbering=true]{bengali}
%++++++++++++++++++++++
\newfontfamily\qbengalifont[Renderer=HarfBuzz,Script=Bengali,AutoFakeBold=4.0,AutoFakeSlant=0.4]{Kalpurush}
\newfontface\bfont{\detokenize{Charu_Chandan_3D_Unicode-Regular}}[Extension=.ttf,
Path=C:/Windows/Fonts/,
Renderer=HarfBuzz,
Script=Bengali,
UprightFont=*,
Colour=blue,]
\newfontfamily\qfall{FreeSerif}[Colour=violet]
%\setTransitionsForLatin{\begin{latin}}{\end{latin}}
%\setTransitionsForLatin{}{}
%++++++++++++++++++++++++++++++++++++
%number all levels
% \setcounter{secnumdepth}{5}
%     \setotherlanguage{english}

% new font for quotation
\newfontfamily\quotefont[%
    % Scale= 1.1,
    % WordSpace=1.4,
    % AutoFakeSlant=1.2,
    % AutoFakeBold=1.2
    ]{Noto Serif}  % My Type Of Font font: https://www.1001freefonts.com/my-type-of-font.font 

% A chapquote environment for chapter quotes
\newenvironment{chapquote}[2][2em]
{
\begingroup
\setlength{\@tempdima}{#1}%
    \def\chapquote@author{#2}%
    \parshape 1 \@tempdima \dimexpr\textwidth-2\@tempdima\relax%
%    \uccoff \quotefont 
\setTransitionsForLatin{\qfall}{\bfont}
%%\setTransitionsForBengali{\bfont}{\qfall}
\setTransitionTo{Bengali}{\bfont}
%\setTransitionTo{Latin}{\qfall}
}
{\par\medskip\hfill — %\uccoff — \uccon
 \chapquote@author\hspace*{\@tempdima}\par\bigskip
\endgroup}  
\makeatother
%^^^^^^^^^^^^^^^^
\begin{document}

আমার পছন্দের একটা উক্তি হলঃ 
%\uccoff

\bigskip
\bigskip
\begin{chapquote}{কার্ল সেগান (Carl Sagan)}
\begin{latin}
    One glance at a book and you hear the voice of another person, perhaps someone dead for 1000 years. To read is to voyage through time.
\end{latin}
\end{chapquote}
%\uccon

%\vspace{4em}
\bigskip
\bigskip
এটার বাংলা অনুবাদ করলে দাঁড়ায় এমনঃ 

\bigskip
%\uccoff
\begin{chapquote}{কার্ল সেগান (Carl Sagan)}
%\setTransitionTo{Bengali}{\qbengalifont}
%\setTransitionTo{BasicLatin}{\qfall}
%\bfont 
    একটি বইয়ের পাতায় এক নজর তাকালে আপনি অন্য ব্যক্তির কণ্ঠ শুনতে পান, সেই ব্যক্তি হয়তো ১০০০ বছর আগে মারা গিয়েছেন। বই-পড়ার মাধ্যমে সময়-ভ্রমণের সুযোগ হয়।
\end{chapquote}
%\uccon

এটার বাংলা অনুবাদ করলে দাঁড়ায় এমনঃ 


\end{document}
4
  • Thank you so much. But as I said in my question, I like to keep the quote author in the default font (latexbangla setting) and add an optional argument for quote-source (at the next line of the quote author). Can you kindly show these too in your answer?
    – raf
    Jun 3, 2021 at 7:48
  • 1
    I don't fully understand: should there be 4, 6, or 8 components in the environment? Can you do a mock-up or illustration or similar?
    – Cicada
    Jun 3, 2021 at 8:05
  • okay, I am going to add my desired output to the question clarification.
    – raf
    Jun 3, 2021 at 8:08
  • I have updated the question, kindly check it.
    – raf
    Jun 3, 2021 at 8:31
0

Instead of using/correcting the chapquote environment, I have obtained the desired output by making two custom commands :

  1. \qtext command for changing to a different font
  2. \chapquote command for the quote structure

Here's the MWE:

test_quote.sty

\setlength{\parindent}{0pt} 

\RequirePackage[banglamainfont=Kalpurush,   % Kalpurush font: https://www.omicronlab.com/bangla-fonts.html 
                banglattfont=Kalpurush,
               ]{latexbangla}
\setdefaultlanguage[numerals=Bengali,
changecounternumbering=true]{bengali}

\RequirePackage{lipsum}

\newfontfamily\quotefont[%
    % Scale= 1.1,
    % WordSpace=1.4,
    % AutoFakeSlant=1.2,
    % AutoFakeBold=1.2
    ]{[mytype]}  % My Type Of Font font: https://www.1001freefonts.com/my-type-of-font.font     
   
% Command for the different font
\newcommand\qtext[1]{{\normalfont \uccoff \quotefont #1 \uccon}}

% Command for the quote
\NewDocumentCommand\Chapquote{mmO{}}{
        \begin{quotation} 
              \noindent  \itshape{#1} \vspace*{-0.5\baselineskip} 
                \begin{flushright} 
                        \textemdash \, \normalfont{#2} \\ \vspace*{-0.1\baselineskip} 
                        \footnotesize\itshape{#3}
                \end{flushright} 
        \end{quotation} }                              

test_quote.tex

% !TEX program = xelatex
\documentclass[12pt, oneside]{book}
\usepackage{test_quote}

\begin{document}

আমার পছন্দের একটা উক্তি হলঃ 
\chapquote{One glance at a book and you hear the voice of another person, perhaps someone dead for 1000 years. \qtext{To read is to voyage through time.}
}{কার্ল সেগান (Carl Sagan)}
[The Source of the quote]

এটার বাংলা অনুবাদ করলে দাঁড়ায় এমনঃ 
\chapquote{একটি বইয়ের পাতায় এক নজর তাকালে আপনি অন্য ব্যক্তির কণ্ঠ শুনতে পান, সেই ব্যক্তি হয়তো ১০০০ বছর আগে মারা গিয়েছেন। বই-পড়ার মাধ্যমে সময়-ভ্রমণের সুযোগ হয়।
}{কার্ল সেগান (Carl Sagan)}
% [The Source of the quote]     % as the quote source argument is supposed to be optional 

\lipsum

\end{document}

And here's the output: Output of my MWE

I am quite satisfied with this custom command method and its output. But still, I am looking for help for the question's chapquote environment so that it can generate a similar output.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .