-
Notifications
You must be signed in to change notification settings - Fork 7
/
latexbangla.sty
226 lines (189 loc) · 7.22 KB
/
latexbangla.sty
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
% ----------------------------------------------------------------
% LaTeXbangla package - Enhanced LaTeX integration for Bangla
% E-mail: [email protected]
% Released under the LaTeX Project Public License v1.3c or later
% See http://www.latex-project.org/lppl.txt
% ----------------------------------------------------------------
% This package simplifies the process of writing Bangla in LaTeX and
% addresses most of the common typesetting issues. Additional features
% include automatic transition between languages and many more. (See
% examples) The user can just type in usual LaTeX syntax and expect
% everything to work as it should.
% ------------------------------------------------------------------
% Copyright (C) 2016-9 by Adib Hasan [email protected]
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License (LPPL), either
% version 1.3c of this license or (at your option) any later
% version. The latest version of this license is in the file:
% http://www.latex-project.org/lppl.txt
% This work is "maintained" (as per LPPL maintenance status) by
% Adib Hasan
% This work consists of the files: latexbangla.sty,
% latexbangla.tex, and
% latexbangla.pdf
%
%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{latexbangla_exp}[2016/10/31 v0.2 Enhanced LaTeX integration for Bangla]
\RequirePackage{polyglossia, fontspec, xkeyval, ifxetex}
% Because this package depends on ucharclasses which itself
% requires XeTeX's interchar classes
\RequireXeTeX
% I have personally tuned some parameters for the following Bangla Fonts so that
% they blend well with the English font. Other banglafonts *are* supported but
% might look out of shape before you tune the following parameters.
\def\@@Kalpurush{Kalpurush}
\def\@Kalpurush#1{
\ifcase#1{Kalpurush} % name
\or{MatchLowercase} % Scale
\or{1.1} % main WordSpace
\or{1.5} % tt WordSpace
\else\fi
}
\def\@@SiyamRupali{SiyamRupali}
\def\@SiyamRupali#1{
\ifcase#1{SiyamRupali} % name
\or{0.8} % Scale
\or{1.2} % main WordSpace
\or{1.8} % tt WordSpace
\else\fi
}
\def\@@SolaimanLipi{SolaimanLipi}
\def\@SolaimanLipi#1{
\ifcase#1{SolaimanLipi} % name
\or{0.89} % Scale
\or{1.5} % main WordSpace
\or{2.1} % tt WordSpace
\else\fi
}
% package options
\DeclareOptionX{banglamainfont}{%
\if\relax\detokenize{#1}\relax
\errmessage{Bangla main font not defined}
\else
\def\bm@name{#1}
\def\bm@@name{bmfont}
\bm@init{\bm@name}
\fi
}
\DeclareOptionX{banglattfont}{%
\if\relax\detokenize{#1}\relax
\errmessage{Bangla tt font not defined}
\else
\def\btt@name{#1}
\def\btt@@name{bttfont}
\btt@init{\btt@name}
\fi
}
% should translate counter numbers (eg. page number, section number) to bangla?
\newif\ifchange@num
\change@numtrue
\DeclareOptionX{changecounternumbering}{
\if\relax\detokenize{#1}\relax\fi
\ifcase#1\change@numfalse\fi
}
% set bangla main font with given settings
\def\bm@init#1{%
% if Kalpurush
\ifx#1\@@Kalpurush%
\def\bm@scale{\@Kalpurush{1}}%
\def\bm@wordspace{\@Kalpurush{2}}%
% else if SiyamRupali
\else\ifx#1\@@SiyamRupali%
\def\bm@scale{\@SiyamRupali{1}}%
\def\bm@wordspace{\@SiyamRupali{2}}%
% else if SolaimanLipi
\else\ifx#1\@@SolaimanLipi%
\def\bm@scale{\@SolaimanLipi{1}}%
\def\bm@wordspace{\@SolaimanLipi{2}}%
% else, my best bet is MatchLowercase with Latin,
% but that does not quite work all the time
\else
\def\bm@scale{MatchLowercase}%
\def\bm@wordspace{1}%
\fi\fi\fi%
}
% set bangla tt font with given settings
\def\btt@init#1{%
% if Kalpurush
\ifx#1\@@Kalpurush%
\def\btt@scale{\@Kalpurush{1}}%
\def\btt@wordspace{\@Kalpurush{3}}%
% else if SiyamRupali
\else\ifx#1\@@SiyamRupali%
\def\btt@scale{\@SiyamRupali{1}}%
\def\btt@wordspace{\@SiyamRupali{3}}%
% else if SolaimanLipi
\else\ifx#1\@@SolaimanLipi%
\def\btt@scale{\@SolaimanLipi{1}}%
\def\btt@wordspace{\@SolaimanLipi{3}}%
% else, my best bet is MatchLowercase with Latin,
% but that does not quite work all the time
\else%
\def\btt@scale{MatchLowercase}%
\def\btt@wordspace{1.2}%
\fi\fi\fi%
}
\ProcessOptionsX\relax
% Polyglossia settings
\ifchange@num
\setmainlanguage[changecounternumbering=false]{bengali}
\else
\setmainlanguage{bengali}
\fi
% define fontfamilies to be used by polyglossia
% Note: you can change the level of boldness and slant
\newfontfamily\bengalifont[%
Script=Bengali,%
Scale=\bm@scale,%
NFSSFamily=\bm@@name,%
WordSpace=\bm@wordspace,%
AutoFakeSlant=0.15,
AutoFakeBold=2.5
]{[\bm@name]}
\newfontfamily\bengalifonttt[%
Script=Bengali,%
Scale=\btt@scale,%
NFSSFamily=\btt@@name,
WordSpace=\btt@wordspace,%
AutoFakeSlant=0.15,
AutoFakeBold=2.5
]{[\btt@name]}
% ---- ----- ----- ----
% Use Latin Modern for English text. Note this will override settings from other font packages
% like `courier', `palatino' etc. If you don't like this feature, comment out \setTransitionsForLatin
% define a new environment latin with Latin Modern
% you may load another English font with \newfontfamily (see above) and use it here
\newenvironment{latin}{\fontencoding{OT1}\ifx\f@family\btt@@name\fontfamily{lmtt}\else\fontfamily{lmr}\fi\selectfont}\relax
% Devanagari is required since Bangla fullstop dari ("0964) is in Devanagari block of Unicode
\RequirePackage[Latin, Bengali, Devanagari]{ucharclasses}
% When latin text is encountered, surround it with \begin{latin} and \end{latin}
\setTransitionsForLatin{\begin{latin}}{\end{latin}}
% ---- ---- ---- ----- -----
% two commands to convert counters and numerals to bangla
% uses Polyglossia's internal counter converters
% counter converter
\def\tobangla#1{\expandafter\bengalinumber\csname c@#1\endcsname}
% numeral converter
\def\numtobangla#1{\bengalinumber#1\@nil}
% converting all the useful counters not handled by polyglossia to bangla
\renewcommand{\thechapter}{\tobangla{chapter}}
\renewcommand{\theequation}{\thechapter.\tobangla{equation}}
\renewcommand{\thefigure}{\thechapter.\tobangla{figure}}
\renewcommand{\theenumi}{\tobangla{enumi}}
\renewcommand{\theenumii}{\tobangla{enumii}}
\renewcommand{\theenumiii}{\tobangla{enumiii}}
\renewcommand{\thefootnote}{\tobangla{footnote}}
% there is no glyph for bullet in bangla fonts
% so change list labels to $\bullet$
\renewcommand\labelitemi{$\bullet$}
% correct captions in polyglossia
\addto\captionsbengali{\renewcommand\abstractname{সারসংক্ষেপ}}
\addto\captionsbengali{\renewcommand\bibname{গ্রন্থসূত্র}}
\addto\captionsbengali{\renewcommand{\figurename}{চিত্র}}
% better support for accented letters
% \RequirePackage{xunicode}
% to allow escape codes. Ex: use \escape{\"{o}} for ő.
% See the full list here: https://en.wikibooks.org/wiki/LaTeX/Special_Characters#Escaped_codes
\newcommand{\escape}[1]{\uccoff\begin{latin}{#1}\end{latin}\uccon}
\endinput