TransWikia.com

Configuring quote environment for bilingual writing

TeX - LaTeX Asked on July 30, 2021

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
newfontfamilyquotefont[%
    % 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}%
    defchapquote@author{#2}%
    parshape 1 @tempdima dimexprtextwidth-2@tempdimarelax%
    uccoff quotefont 
}
{parhfill uccoff — uccon chapquote@authorhspace*{@tempdima}parbigskip}  

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

2 Answers

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}
%++++++++++++++++++++++
newfontfamilyqbengalifont[Renderer=HarfBuzz,Script=Bengali,AutoFakeBold=4.0,AutoFakeSlant=0.4]{Kalpurush}
newfontfacebfont{detokenize{Charu_Chandan_3D_Unicode-Regular}}[Extension=.ttf,
Path=C:/Windows/Fonts/,
Renderer=HarfBuzz,
Script=Bengali,
UprightFont=*,
Colour=blue,]
newfontfamilyqfall{FreeSerif}[Colour=violet]
%setTransitionsForLatin{begin{latin}}{end{latin}}
%setTransitionsForLatin{}{}
%++++++++++++++++++++++++++++++++++++
%number all levels
% setcounter{secnumdepth}{5}
%     setotherlanguage{english}

% new font for quotation
newfontfamilyquotefont[%
    % 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}%
    defchapquote@author{#2}%
    parshape 1 @tempdima dimexprtextwidth-2@tempdimarelax%
%    uccoff quotefont 
setTransitionsForLatin{qfall}{bfont}
%%setTransitionsForBengali{bfont}{qfall}
setTransitionTo{Bengali}{bfont}
%setTransitionTo{Latin}{qfall}
}
{parmedskiphfill — %uccoff — uccon
 chapquote@authorhspace*{@tempdima}parbigskip
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}

Answered by Cicada on July 30, 2021

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}

newfontfamilyquotefont[%
    % 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
newcommandqtext[1]{{normalfont uccoff quotefont #1 uccon}}

% Command for the quote
NewDocumentCommandChapquote{mmO{}}{
        begin{quotation} 
              noindent  itshape{#1} vspace*{-0.5baselineskip} 
                begin{flushright} 
                        textemdash , normalfont{#2}  vspace*{-0.1baselineskip} 
                        footnotesizeitshape{#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.

Answered by raf on July 30, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP