debian/changelog (7.1.9-1)
[software/sisu] / lib / sisu / texpdf_format.rb
1 # encoding: utf-8
2 =begin
3
4 * Name: SiSU
5
6 ** Description: documents, structuring, processing, publishing, search
7 *** LaTeX formatting template, unicode utf-8 version, used for pdf
8
9 ** Author: Ralph Amissah
10 [ralph@amissah.com]
11 [ralph.amissah@gmail.com]
12
13 ** Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
14 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Ralph Amissah,
15 All Rights Reserved.
16
17 ** License: GPL 3 or later:
18
19 SiSU, a framework for document structuring, publishing and search
20
21 Copyright (C) Ralph Amissah
22
23 This program is free software: you can redistribute it and/or modify it
24 under the terms of the GNU General Public License as published by the Free
25 Software Foundation, either version 3 of the License, or (at your option)
26 any later version.
27
28 This program is distributed in the hope that it will be useful, but WITHOUT
29 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
30 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
31 more details.
32
33 You should have received a copy of the GNU General Public License along with
34 this program. If not, see [http://www.gnu.org/licenses/].
35
36 If you have Internet connection, the latest version of the GPL should be
37 available at these locations:
38 [http://www.fsf.org/licensing/licenses/gpl.html]
39 [http://www.gnu.org/licenses/gpl.html]
40
41 ** SiSU uses:
42 * Standard SiSU markup syntax,
43 * Standard SiSU meta-markup syntax, and the
44 * Standard SiSU object citation numbering and system
45
46 ** Hompages:
47 [http://www.jus.uio.no/sisu]
48 [http://www.sisudoc.org]
49
50 ** Git
51 [http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=summary]
52 [http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=blob;f=lib/sisu/texpdf_format.rb;hb=HEAD]
53
54 =end
55 module SiSU_TeX_Pdf
56 require_relative 'texpdf_parts' # texpdf_parts.rb
57 @@table_pg_break_counter=1
58 class BareUrls
59 include SiSU_Parts_TeXpdf
60 def initialize(md,dob=nil)
61 @md,@dob=md,dob
62 end
63 def bare_urls
64 @dob.obj=@dob.obj.gsub(/#{Mx[:url_o]}([a-zA-Z0-9._-]+\@[a-zA-Z0-9_-]+?\.[a-zA-Z0-9._-]+)#{Mx[:url_c]}/,
65 "#{url_decoration.tex_open}\\begin{scriptsize}\\email{\\1}#{url_decoration.tex_close}")
66 @dob.tmp=@dob.tmp.gsub(/(^|[^\\])_/m,'\1\_'). #watch may not work
67 gsub(/(^|[^#{Mx[:lnk_c]}])#{Mx[:url_o]}_?(?:\\?_)?(\S+?)#{Mx[:url_c]}/m,
68 "\\1#{url_decoration.tex_open}\\begin{scriptsize}\\url{\\2}\\end{scriptsize}#{url_decoration.tex_close}")
69 @dob
70 end
71 def bare_urls_in_code
72 @dob.tmp=@dob.tmp.gsub(/(^|[^\\])_/m,'\1\_'). #watch may not work
73 gsub(/(https?:\/\/\S+?)([{]|[.,;)\]]?(?: |$))/m,
74 '\begin{scriptsize}\url{\1}\end{scriptsize}\2')
75 @dob
76 end
77 end
78 class FormatTextObject
79 include SiSU_Parts_TeXpdf
80 attr_accessor :string,:string1,:orientation,:url,:dir,:tex
81 @@sys=SiSU_Env::SystemCall.new
82 @@tex_pattern_margin_number=/\\begin\{tiny\}\\hspace\{0mm\}\\end\{tiny\}\{\\marginpar.+?\}\}\}/
83 @@tableheader={
84 'a4' => { p: 0, l: 0 },
85 'a5' => { p: 0, l: 0 },
86 'b5' => { p: 0, l: 0 },
87 'letter' => { p: 0, l: 0 },
88 'legal' => { p: 0, l: 0 }
89 }
90 @@sys=SiSU_Env::SystemCall.new
91 def initialize(md,dob=nil)
92 @md,@dob=md,dob
93 if defined? @md.image \
94 and @md.image =~/center/
95 @center_begin,@center_end='\begin{center}','\end{center}'
96 else @center_begin,@center_end='',''
97 end
98 @start_table=''
99 @tx=SiSU_Env::GetInit.new.tex
100 @env ||=SiSU_Env::InfoEnv.new(@md.fns)
101 @tex2pdf=@@tex3pdf ||=SiSU_Env::SystemCall.new.tex2pdf_engine
102 @make ||=SiSU_Env::ProcessingSettings.new(@md)
103 end
104 def ocn_display(dob)
105 show_ocn=(@make.build.ocn?) \
106 ? dob.ocn
107 : ''
108 "\\begin{tiny}\\hspace{0mm}\\end{tiny}{\\marginpar{\\begin{tiny}\\hspace{0mm}\\hypertarget{#{dob.ocn}}{#{show_ocn}}\\end{tiny}}}" #ocn object citation numbering
109 end
110 def table_special_characters(r)
111 r=r.gsub(/#{Mx[:tc_p]}/mu,'&').
112 gsub(/#{Mx[:tc_c]}/m,'\\\\\\').
113 gsub(/%/,'\%').
114 gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/,'\begin{bfseries}\1 \end{bfseries}').
115 gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/,'\emph{\1}').
116 gsub(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/,'\uline{\1}'). # ulem
117 gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,"``\\1''"). # quote #CHECK
118 gsub(/#{Mx[:fa_insert_o]}(.+?)#{Mx[:fa_insert_c]}/,'\uline{\1}'). # ulem
119 gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/,'\sout{\1}'). # ulem
120 gsub(/#{Mx[:fa_superscript_o]}(.+?)#{Mx[:fa_superscript_c]}/,"\$^{\\textrm{\\1}}\$").
121 gsub(/#{Mx[:fa_subscript_o]}(.+?)#{Mx[:fa_subscript_c]}/,"\$_{\\textrm{\\1}}\$")
122 end
123 def longtable_landscape
124 end_table='\end{longtable}'
125 row_break='\\\\\\'
126 if @dob.is==:table
127 tw=case @dob.tmp[:paper_size]
128 when /a4/i then @tx.a4.landscape.w #European default, SiSU default
129 when /letter/i then @tx.letter.landscape.w #U.S. default
130 when /legal/i then @tx.legal.landscape.w #U.S. alternative
131 when /book|b5/i then @tx.b5.landscape.w #book default - larger
132 when /a5/i then @tx.a5.landscape.w
133 else @tx.a4.landscape.w #default currently A4
134 end
135 textwidth=(tw.to_i/2) - 24
136 colW=[]
137 colW << '{'
138 @dob.widths.each do |x|
139 x=(x.to_i * textwidth)/100
140 col_w=x.to_s # x.gsub(/.+/,'l\|') #unless x.nil?
141 colW << "p{#{col_w}mm}" if col_w
142 end
143 colW << '}'
144 colW=colW.join
145 start_table="\n\\setlength{\\LTleft}{0pt}\n\\setlength{\\LTright}{\\fill}\n" +
146 "\\begin{tiny}\n\\begin{longtable}#{colW}\n"
147 rows=@dob.obj.split(/#{Mx[:br_nl]}/)
148 if @dob.head_ #result imperfect, check on
149 rows[0]=rows[0].gsub(/(^|.+?)(?:#{Mx[:tc_p]}|$)/u,'\bfseries \1&').
150 gsub(/&\s*$/," #{row_break} \\hline\\endhead #{row_break}")
151 end
152 rows_new=[]
153 rows.each do |r|
154 r=table_special_characters(r)
155 r=r.gsub(/$/," #{row_break}\n") unless r =~/#{row_break*2}$/
156 if r=~/\<!f(.+?)!\>/ # not tested table footer if any
157 tablefoot=$1
158 r=r.gsub(/\<!f(.+?)!\>/,'')
159 r="#{r} \\multicolumn{#{@dob.cols}}{l}{\\tiny #{tablefoot}} \\\\ \\hline\n\\endfoot\n\\hline\n"
160 end
161 rows_new << r
162 end
163 table=rows_new.join #@dob[:ao].obj=rows.join
164 ocn_display(@dob) + start_table + table + " #{end_table}\n\\end{tiny}"
165 else ''
166 end
167 end
168 def longtable_portrait
169 end_table='\end{longtable}'
170 row_break='\\\\\\'
171 if @dob.is==:table
172 tw=case @dob.tmp[:paper_size]
173 when /a4/i then @tx.a4.portrait.w #European default, SiSU default
174 when /letter/i then @tx.letter.portrait.w #U.S. default
175 when /legal/i then @tx.legal.portrait.w #U.S. alternative
176 when /book|b5/i then @tx.b5.portrait.w #book default - larger
177 when /a5/i then @tx.a5.portrait.w
178 else @tx.a4.portrait.w #default currently A4
179 end
180 textwidth=tw.to_i - 20
181 colW=[]
182 colW << '{'
183 @dob.widths.each do |x|
184 x=(x.to_i * textwidth)/100 #x=(x.to_i/100.0 * 160)
185 col_w=x.to_s # x.gsub(/.+/,'l\|') #unless x.nil?
186 colW << "p{#{col_w}mm}" if col_w
187 end
188 colW << '}'
189 colW=colW.join
190 start_table="\n\\setlength{\\LTleft}{0pt}\n\\setlength{\\LTright}{\\fill}\n" +
191 "\\begin{tiny}\n\\begin{longtable}#{colW}\n"
192 rows=@dob.obj.split(/#{Mx[:br_nl]}/)
193 if @dob.head_
194 rows[0]=rows[0].gsub(/(^|.+?)(?:#{Mx[:tc_p]}|$)/u,'\bfseries \1&').
195 gsub(/&\s*$/," #{row_break} \\hline\\endhead #{row_break}")
196 end
197 rows_new=[]
198 rows.each do |r|
199 r=table_special_characters(r)
200 r=r.gsub(/$/," #{row_break}\n") unless r =~/#{row_break*2}$/
201 if r=~/\<!f(.+?)!\>/ # not tested table footer if any
202 tablefoot=$1
203 r=r.gsub(/\<!f(.+?)!\>/,'')
204 r="#{r} \\multicolumn{#{@dob.cols}}{l}{\\tiny #{tablefoot}} \\\\ \\hline\n\\endfoot\n\\hline\n"
205 end
206 rows_new << r
207 end
208 table=rows_new.join #@dob[:ao].obj=rows.join
209 ocn_display(@dob) + start_table + table + " #{end_table}\n\\end{tiny}"
210 else ''
211 end
212 end
213 def remove_footnotes(cont_ln)
214 cont_ln=if cont_ln =~/\\[Ff]ootnote/m
215 cont_ln.gsub(/\s*\\[Ff]ootnote\[\d+\]\{%\s+.+?\}\s*/m,' ').
216 gsub(/\s*\\[Ff]ootnote[A]\{[*+]+\d*\}\{%\S+.+?\}\s*/m,' ')
217 else cont_ln
218 end
219 end
220 def title_level_A
221 dob=@dob
222 dob.tmp=dob.tmp.strip if dob.tmp
223 dob.tmp=dob.tmp.gsub(/\\begin\{(bfseries|itshape)\}(.+?)\\end\{\1\}/m,'\2').
224 gsub(/#{Mx[:url_o]}|#{Mx[:url_c]}/,'')
225 cont_ln=dob.tmp.dup
226 cont_ln=cont_ln.gsub(/\\begin\{(monosp)\}(.+?)\\end\{\1\}/m,'\2').
227 gsub(@@tex_pattern_margin_number,'')
228 cont_ln=remove_footnotes(cont_ln)
229 cont_ln=cont_ln.gsub(/\{[\\]+(&)\}/,'\\1')
230 titleset=''
231 dob.tmp=dob.tmp.gsub(/^(.*)\n?$/m,
232 "#{titleset}\\part*{\\1}
233 \\markboth{#{@md.title.full}}\n")
234 dob
235 end
236 def section_heading_level(dob)
237 dob.tmp=dob.tmp.strip if dob.tmp
238 dob.tmp=dob.tmp.gsub(/\\begin\{(bfseries|itshape)\}(.+?)\\end\{\1\}/m,'\2').
239 gsub(/#{Mx[:url_o]}|#{Mx[:url_c]}/,'')
240 cont_ln=dob.tmp.dup
241 cont_ln=cont_ln.gsub(/\\begin\{(monosp)\}(.+?)\\end\{\1\}/m,'\2').
242 gsub(@@tex_pattern_margin_number,'')
243 cont_ln=remove_footnotes(cont_ln)
244 cont_ln=cont_ln.gsub(/\{[\\]+(&)\}/,'\\1')
245 dob.tmp=dob.tmp.gsub(/^(.*)\n?$/m,
246 "\\clearpage
247 \\part*{\\1}
248 \\addcontentsline{toc}{part}{#{cont_ln}}
249 \\markboth{#{@md.title.full}}\n")
250 dob
251 end
252 def heading_dev_null(dob)
253 dob.tmp,dob.obj='',''
254 dob
255 end
256 def heading_sublevels(dob)
257 if dob.lv=='1'
258 sect='section'
259 tocadd=%{\\addcontentsline{toc}{section}}
260 pre=''
261 post=''
262 headadd=%{\n\\markright{#{@md.title.full}}}
263 elsif dob.lv=='2'
264 sect='subsection'
265 tocadd=%{\\addcontentsline{toc}{subsection}}
266 pre=''
267 post=" \\\\\n"
268 headadd=''
269 elsif dob.lv=='3'
270 sect='subsubsection'
271 tocadd=%{\\addcontentsline{toc}{subsubsection}}
272 pre='' #pre='~~~~'
273 post=" \\\\\n"
274 headadd=''
275 end
276 dob.tmp=dob.tmp.strip if dob.tmp
277 dob.tmp=dob.tmp.gsub(/\\begin\{(bfseries|itshape)\}(.+?)\\end\{\1\}/m,'\2').
278 gsub(/#{Mx[:url_o]}|#{Mx[:url_c]}/,'')
279 cont_ln=dob.tmp.dup
280 cont_ln=cont_ln.gsub(/\\begin\{(monosp)\}(.+?)\\end\{\1\}/m,'\2').
281 gsub(@@tex_pattern_margin_number,'').
282 gsub(/#{Tex[:backslash]*2}/,"#{Tex[:backslash]*4}"). # added w42
283 gsub(/\\footnote\[\d+\]\{%.+?\\end\{scriptsize\}\s*\}/m,''). #arbitrary bugfix, revisit should not be necessary, eg. wta.1994 2004w22
284 gsub(/\\Footnote[A]\{[*+]+\d*\}\{%.+?\\end\{scriptsize\}\s*\}/m,'') #arbitrary bugfix, revisit should not be necessary, eg. wta.1994 2004w22
285 if dob.name =~/endnotes/
286 dob.tmp=dob.tmp.gsub(/.+/m,'')
287 end
288 cont_ln=remove_footnotes(cont_ln)
289 cont_ln=cont_ln.gsub(/\{[\\]+(&)\}/,'\\1')
290 dob.tmp=dob.tmp.gsub(/^(.*)?\n?$/m,
291 "\\#{sect}*{\\1}
292 #{tocadd}{#{pre}#{cont_ln}#{post}}#{headadd}")
293 dob
294 end
295 def section_heading_level_B
296 section_heading_level(@dob)
297 end
298 def section_heading_level_C
299 section_heading_level(@dob)
300 end
301 def section_heading_level_D
302 section_heading_level(@dob)
303 end
304 def heading_level_1
305 if not @dob.use_ == :dummy
306 heading_sublevels(@dob)
307 else
308 heading_dev_null(@dob)
309 end
310 end
311 def heading_level_2
312 heading_sublevels(@dob)
313 end
314 def heading_level_3
315 heading_sublevels(@dob)
316 end
317 def heading_level_4
318 heading_sublevels(@dob)
319 end
320 def hang
321 case @dob.indent
322 when /0/
323 case @dob.hang
324 when /0/ then indent,hang='0mm', '0mm'
325 when /1/ then indent,hang='0mm','10mm'
326 when /2/ then indent,hang='0mm','20mm'
327 when /3/ then indent,hang='0mm','30mm'
328 when /4/ then indent,hang='0mm','40mm'
329 when /5/ then indent,hang='0mm','50mm'
330 when /6/ then indent,hang='0mm','60mm'
331 when /7/ then indent,hang='0mm','70mm'
332 when /8/ then indent,hang='0mm','80mm'
333 when /9/ then indent,hang='0mm','90mm'
334 end
335 when /1/
336 case @dob.hang
337 when /0/ then indent,hang='10mm','-10mm'
338 when /1/ then indent,hang='10mm', '0mm'
339 when /2/ then indent,hang='10mm', '10mm'
340 when /3/ then indent,hang='10mm', '20mm'
341 when /4/ then indent,hang='10mm', '30mm'
342 when /5/ then indent,hang='10mm', '40mm'
343 when /6/ then indent,hang='10mm', '50mm'
344 when /7/ then indent,hang='10mm', '60mm'
345 when /8/ then indent,hang='10mm', '70mm'
346 when /9/ then indent,hang='10mm', '80mm'
347 end
348 when /2/
349 case @dob.hang
350 when /0/ then indent,hang='20mm','-20mm'
351 when /1/ then indent,hang='20mm','-10mm'
352 when /2/ then indent,hang='20mm', '0mm'
353 when /3/ then indent,hang='20mm', '10mm'
354 when /4/ then indent,hang='20mm', '20mm'
355 when /5/ then indent,hang='20mm', '30mm'
356 when /6/ then indent,hang='20mm', '40mm'
357 when /7/ then indent,hang='20mm', '50mm'
358 when /8/ then indent,hang='20mm', '60mm'
359 when /9/ then indent,hang='20mm', '70mm'
360 end
361 when /3/
362 case @dob.hang
363 when /0/ then indent,hang='30mm','-30mm'
364 when /1/ then indent,hang='30mm','-20mm'
365 when /2/ then indent,hang='30mm','-10mm'
366 when /3/ then indent,hang='30mm', '0mm'
367 when /4/ then indent,hang='30mm', '10mm'
368 when /5/ then indent,hang='30mm', '20mm'
369 when /6/ then indent,hang='30mm', '30mm'
370 when /7/ then indent,hang='30mm', '40mm'
371 when /8/ then indent,hang='30mm', '50mm'
372 when /9/ then indent,hang='30mm', '60mm'
373 end
374 when /4/
375 case @dob.hang
376 when /0/ then indent,hang='40mm','-40mm'
377 when /1/ then indent,hang='40mm','-30mm'
378 when /2/ then indent,hang='40mm','-20mm'
379 when /3/ then indent,hang='40mm','-10mm'
380 when /4/ then indent,hang='40mm', '0mm'
381 when /5/ then indent,hang='40mm', '10mm'
382 when /6/ then indent,hang='40mm', '20mm'
383 when /7/ then indent,hang='40mm', '30mm'
384 when /8/ then indent,hang='40mm', '40mm'
385 when /9/ then indent,hang='40mm', '50mm'
386 end
387 when /5/
388 case @dob.hang
389 when /0/ then indent,hang='50mm','-50mm'
390 when /1/ then indent,hang='50mm','-40mm'
391 when /2/ then indent,hang='50mm','-30mm'
392 when /3/ then indent,hang='50mm','-20mm'
393 when /4/ then indent,hang='50mm','-10mm'
394 when /5/ then indent,hang='50mm', '0mm'
395 when /6/ then indent,hang='50mm', '10mm'
396 when /7/ then indent,hang='50mm', '20mm'
397 when /8/ then indent,hang='50mm', '30mm'
398 when /9/ then indent,hang='50mm', '40mm'
399 end
400 when /6/
401 case @dob.hang
402 when /0/ then indent,hang='60mm','-60mm'
403 when /1/ then indent,hang='60mm','-50mm'
404 when /2/ then indent,hang='60mm','-40mm'
405 when /3/ then indent,hang='60mm','-30mm'
406 when /4/ then indent,hang='60mm','-20mm'
407 when /5/ then indent,hang='60mm','-10mm'
408 when /6/ then indent,hang='60mm', '0mm'
409 when /7/ then indent,hang='60mm', '10mm'
410 when /8/ then indent,hang='60mm', '20mm'
411 when /9/ then indent,hang='60mm', '30mm'
412 end
413 when /7/
414 case @dob.hang
415 when /0/ then indent,hang='70mm','-70mm'
416 when /1/ then indent,hang='70mm','-60mm'
417 when /2/ then indent,hang='70mm','-50mm'
418 when /3/ then indent,hang='70mm','-40mm'
419 when /4/ then indent,hang='70mm','-30mm'
420 when /5/ then indent,hang='70mm','-20mm'
421 when /6/ then indent,hang='70mm','-10mm'
422 when /7/ then indent,hang='70mm', '0mm'
423 when /8/ then indent,hang='70mm', '10mm'
424 when /9/ then indent,hang='70mm', '20mm'
425 end
426 when /8/
427 case @dob.hang
428 when /0/ then indent,hang='80mm','-80mm'
429 when /1/ then indent,hang='80mm','-70mm'
430 when /2/ then indent,hang='80mm','-60mm'
431 when /3/ then indent,hang='80mm','-50mm'
432 when /4/ then indent,hang='80mm','-40mm'
433 when /5/ then indent,hang='80mm','-30mm'
434 when /6/ then indent,hang='80mm','-20mm'
435 when /7/ then indent,hang='80mm','-10mm'
436 when /8/ then indent,hang='80mm', '0mm'
437 when /9/ then indent,hang='80mm', '10mm'
438 end
439 when /9/
440 case @dob.hang
441 when /0/ then indent,hang='90mm','-90mm'
442 when /1/ then indent,hang='90mm','-80mm'
443 when /2/ then indent,hang='90mm','-70mm'
444 when /3/ then indent,hang='90mm','-60mm'
445 when /4/ then indent,hang='90mm','-50mm'
446 when /5/ then indent,hang='90mm','-40mm'
447 when /6/ then indent,hang='90mm','-30mm'
448 when /7/ then indent,hang='90mm','-20mm'
449 when /8/ then indent,hang='90mm','-10mm'
450 when /9/ then indent,hang='90mm', '0mm'
451 end
452 end
453 "\\begin{ParagraphHang}{#{indent}}{#{hang}}#{@dob.tmp} \\end{ParagraphHang}}"
454 end
455 def indent
456 indent=case @dob.indent
457 when /1/ then '0mm'
458 when /2/ then '10mm'
459 when /3/ then '20mm'
460 when /4/ then '30mm'
461 when /5/ then '40mm'
462 when /6/ then '50mm'
463 when /7/ then '60mm'
464 when /8/ then '70mm'
465 when /9/ then '80mm'
466 end
467 "\\begin{ParagraphIndent}{#{indent}}#{@dob.tmp} \\end{ParagraphIndent}}"
468 end
469 def bullet
470 blt=if @dob.indent
471 indent=case @dob.indent
472 when /1/ then '0em'
473 when /2/ then '1.0em'
474 when /3/ then '2.0em'
475 when /4/ then '3.0em'
476 when /5/ then '4.0em'
477 when /6/ then '5.0em'
478 when /7/ then '6.0em'
479 when /8/ then '7.0em'
480 when /9/ then '8.0em'
481 else '-1.0em'
482 end
483 "\\begin{Bullet}{#{indent}}$\\txtbullet$\\hspace{\\enspace}#{@dob.tmp}\\end{Bullet}"
484 else
485 "\\begin{Bullet}{-5mm}$\\txtbullet$\\hspace{\\enspace}#{@dob.tmp}\\end{Bullet}"
486 end
487 blt
488 end
489 def symbol_graphic
490 dir=SiSU_Env::InfoEnv.new(@md.fns)
491 image='c_' + /<:=\s*(\S+?)\s*>/m.match(@txt).captures.join + '.png' #watch
492 if FileTest.file?("#{dir.path.image_source_include}/#{image}")
493 @txt.gsub!(/<:=\s*(\S+?)\s*>/,
494 "\\includegraphics*[width=11pt]{#{dir.path.image_source_include}/c_\\1.png}")
495 else
496 SiSU_Screen::Ansi.new(
497 @md.opt.act[:color_state][:set],
498 "ERROR - image:",
499 %{"#{image}" missing},
500 "search path: #{dir.path.image_source_include}"
501 ).error2 unless @md.opt.act[:quiet][:set]==:on
502 @txt.gsub!(/#{Mx[:lnk_o]}\S+\.(png|jpg|gif).+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/,'') # fragile match operator\\ fragile !
503 end
504 end
505 def url_str_internal(str,idx=nil)
506 map_nametags=SiSU_Particulars::CombinedSingleton.instance.get_map_nametags(@md).nametags_map #p map_nametags
507 rgx_url_internal=/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:rel_o]}#?\S+?#{Mx[:rel_c]}/m
508 while str =~/#{Mx[:lnk_o]}([^#{Mx[:lnk_o]}#{Mx[:lnk_c]}]+)#{Mx[:lnk_c]}#{Mx[:rel_o]}:(\S+?)#{Mx[:rel_c]}/m
509 link,url=$1,$2
510 link,url=link.strip,url.strip
511 link.gsub!(/&/,"#{Xx[:protect]}&")
512 url="#{@env.url.root}/" + url
513 str.sub!(/#{Mx[:lnk_o]}[^#{Mx[:lnk_o]}#{Mx[:lnk_c]}]+#{Mx[:lnk_c]}#{Mx[:rel_o]}:\S+?#{Mx[:rel_c]}/m,
514 "#{url_decoration.tex_open}\\href{#{url}}{#{link}}#{url_decoration.tex_close}")
515 end
516 while str =~/#{Mx[:lnk_o]}([^#{Mx[:lnk_o]}#{Mx[:lnk_c]}]+)#{Mx[:lnk_c]}#{Mx[:rel_o]}#?(\S+?)#{Mx[:rel_c]}/m
517 link,url=$1,$2
518 link,url=link.strip,url.strip
519 link.gsub!(/&/,"#{Xx[:protect]}&")
520 url.gsub!(/\\_/,'_')
521 ocn_lnk=if map_nametags[url] \
522 and map_nametags[url][:ocn]
523 map_nametags[url][:ocn]
524 else nil
525 end
526 ocn_lnk=(url=~/^\d+$/ ? url : ocn_lnk)
527 if ocn_lnk and not ocn_lnk.empty?
528 idx \
529 ? (str.sub!(rgx_url_internal,"\\hyperlink{#{ocn_lnk}}{#{link}}"))
530 : (str.sub!(rgx_url_internal,"#{url_decoration.tex_open}\\hyperlink{#{ocn_lnk}}{#{link}}#{url_decoration.tex_close}"))
531 else
532 puts %{name tag: "#{url}" not found}
533 str.sub!(rgx_url_internal,"#{link}")
534 end
535 #[keep] code that follows uses nametags directly, currently nametags converted to their ocn, related code: |texpdf.rb|@|hypertargets|
536 #idx \
537 #? (str.sub!(rgx_url_internal,"\\hyperlink{#{url}}{#{link}}")) \
538 #: (str.sub!(rgx_url_internal,"#{url_decoration.tex_open}\\hyperlink{#{url}}{#{link}}#{url_decoration.tex_close}"))
539 end
540 str=str.gsub(/#{Xx[:protect]}/,'')
541 end
542 def url_str(str)
543 rgx_url_generic=/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/m
544 while str =~rgx_url_generic
545 if str=~rgx_url_generic
546 regx_url=%r/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/m
547 z,url=regx_url.match(str).captures if str =~regx_url
548 url=url.strip
549 link=z.strip
550 link.gsub!(/&/,"#{Xx[:protect]}&")
551 str.sub!(rgx_url_generic,"#{url_decoration.tex_open}\\href{#{url}}{#{link}}#{url_decoration.tex_close}")
552 str=str.gsub(/#{Xx[:protect]}/,'')
553 str
554 else str
555 end
556 str
557 end
558 str
559 end
560 def url_with_txt(dob)
561 rgx_url_generic=/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/m
562 while dob.tmp =~rgx_url_generic
563 if dob.tmp=~rgx_url_generic
564 if dob.tmp =~/#{Mx[:lnk_o]}(?:.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/m
565 regx_url=%r/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/m
566 punctuate=/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/m.match(dob.tmp).captures.join
567 else
568 regx_url=%r/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/m
569 punctuate=''
570 end
571 z,url=regx_url.match(dob.tmp).captures if dob.tmp =~regx_url
572 url=url.strip
573 link=z.strip
574 link.gsub!(/&/,"#{Xx[:protect]}&")
575 dob.tmp.sub!(rgx_url_generic,"#{url_decoration.tex_open}\\href{#{url}}{#{link}}#{url_decoration.tex_close}#{punctuate}")
576 dob.tmp.gsub!(/#{Xx[:protect]}/,'')
577 #dob.tmp=dob.tmp.sub(rgx_url_generic,"#{url_decoration.tex_open}\\href{#{url}}{#{link}}#{url_decoration.tex_close}#{punctuate}").
578 # gsub(/#{Xx[:protect]}/,'')
579 dob
580 else dob
581 end
582 dob
583 end
584 dob
585 end
586 def urls_txt_and_images
587 dob=@dob
588 dir=SiSU_Env::InfoEnv.new(@md.fns)
589 @dm={
590 'a4'=> @tx.a4.landscape.img_px,
591 'letter'=> @tx.letter.landscape.img_px,
592 'legal'=> @tx.legal.landscape.img_px,
593 'b5'=> @tx.b5.landscape.img_px,
594 'a5'=> @tx.a5.landscape.img_px
595 }
596 images_hash={ }
597 generic_rgx=/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image\b)/m
598 rgx_url_generic=/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/m
599 #url_bare_rgx=/#{Mx[:url_o]}\S+?#{Mx[:url_c]}/m
600 url_image_rgx=/#{Mx[:lnk_o]}[a-zA-Z0-9_\\-]+\.(?:png|jpg|gif).+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/m
601 image_rgx=/#{Mx[:lnk_o]}[a-zA-Z0-9_\\-]+\.(?:png|jpg|gif).+?#{Mx[:lnk_c]}image/m
602 @md.papersize_array.each do |ps|
603 images_hash[ps] = dob.tmp
604 while images_hash[ps] =~generic_rgx
605 if dob.tmp =~rgx_url_generic \
606 and dob.tmp !~/\.(?:png|jpg|gif)|#{Mx[:lnk_c]}image\b/m
607 dob=url_with_txt(dob)
608 elsif images_hash[ps]=~generic_rgx
609 if dob.tmp=~rgx_url_generic
610 if images_hash[ps] =~/#{Mx[:lnk_o]}(?:.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/m
611 regx_url=%r/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/m
612 punctuate=/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/m.match(images_hash[ps]).captures.join
613 else
614 regx_url=%r/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/m
615 punctuate=''
616 end
617 z,url=regx_url.match(images_hash[ps]).captures if images_hash[ps] =~regx_url
618 url=url.strip
619 else
620 if images_hash[ps] =~/#{Mx[:lnk_o]}(?:.+?)#{Mx[:lnk_c]}image\.[^'"\s]+?(?:[;.,]?(?:\s|$)|(?:\s|$))/m
621 regx_url=%r/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}image\.[^'"\s]+?(?:[;.,]?(?:\s|$)|(?:\s|$))/m
622 punctuate=/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}image\.[^'"\s]+?([;.,]?(?:\s|$))/m.match(images_hash[ps]).captures.join
623 else
624 regx_url=%r/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}image/m
625 punctuate=''
626 end
627 z=regx_url.match(images_hash[ps])[1] if images_hash[ps] =~regx_url
628 url=''
629 end
630 if images_hash[ps] =~/#{Mx[:lnk_o]}\s*\S+\.?(?:png|jpg|gif)/m \
631 and images_hash[ps]=~/\s+\d+x\d+(\s+|\s*#{Mx[:lnk_c]})/m
632 image=z.scan(/\S+/)[0] #image,x,y=z.scan(/\S+/)
633 image.gsub!(/\\/,'')
634 w=((z =~/\s(\d+)x\d*/) ? z[/\s(\d+)x\d*/,1] : 200)
635 width={}
636 width['a4'] = ((w.to_i > @dm['a4']) ? @dm['a4'] : w)
637 width['letter'] = ((w.to_i > @dm['letter']) ? @dm['letter'] : w)
638 width['legal'] = ((w.to_i > @dm['legal']) ? @dm['legal'] : w)
639 width['a5'] = ((w.to_i > @dm['a5']) ? @dm['a5'] : w)
640 width['b5'] = ((w.to_i > @dm['b5']) ? @dm['b5'] : w)
641 c=z[/``(.+?)''/m,1]
642 hsp="\n{\\color{mywhite} .}&~\n" # ~ character for hardspace
643 caption=(c ? "{\\\\\ \n\\begin{scriptsize}#{hsp*3}#{c}\\end{scriptsize}&}" : '')
644 elsif images_hash[ps] =~/#{Mx[:lnk_o]}\s*(\S+\.?\.(?:png|jpg|gif))/m
645 SiSU_Screen::Ansi.new(
646 @md.opt.act[:color_state][:set],
647 %{document built without image: "#{$1}" as image dimensions not provided (either image not found or neither imagemagick nor graphicsmagick is installed)?\n}
648 ).print_grey #unless @md.opt.act[:quiet][:set]==:on
649 images_hash[ps].gsub!(/#{Mx[:lnk_o]}\s*(\S+\.?\.(?:png|jpg|gif))/,'[image]')
650 end
651 if image #most images fc etc. #% clean up !
652 if FileTest.file?("#{dir.path.image_source_include}/#{image}")
653 case images_hash[ps]
654 when url_image_rgx
655 images_hash[ps].sub!(url_image_rgx,
656 "#{@center_begin}\\\n\\href{#{url}}\n{\\includegraphics*[width=#{width[ps]}pt]{#{dir.path.image_source_include}/#{image}}}#{caption}#{@center_end}")
657 when image_rgx
658 images_hash[ps].sub!(image_rgx,
659 "#{@center_begin}\\\n\\includegraphics*[width=#{width[ps]}pt]{#{dir.path.image_source_include}/#{image}}#{caption}#{@center_end}")
660 end
661 images_hash[ps]
662 elsif @md.opt.f_pth[:pth] =~/\/\S+?\/sisupod\/\S+?\/sisupod\/doc/
663 pt=/(\/\S+?\/sisupod\/\S+?\/sisupod)\/doc/.match(@md.opt.f_pth[:pth])[1]
664 img_src=pt + '/image'
665 if FileTest.file?("#{img_src}/#{image}")
666 case images_hash[ps]
667 when url_image_rgx
668 images_hash[ps].sub!(url_image_rgx,
669 "#{@center_begin}\\\n\\href{#{url}}{\\includegraphics*[width=#{width[ps]}pt]{#{img_src}/#{image}}}#{caption} #{@center_end}")
670 when image_rgx
671 images_hash[ps].sub!(image_rgx,
672 "#{@center_begin}\\\n\\includegraphics*[width=#{width[ps]}pt]{#{img_src}/#{image}}#{caption} #{@center_end}")
673 end
674 images_hash[ps]
675 end
676
677 elsif @md.fns =~/\.(?:ssm\.)?sst$/ \
678 and FileTest.file?("#{dir.path.image_source_include_local}/#{image}")
679 case images_hash[ps]
680 when url_image_rgx
681 images_hash[ps].sub!(url_image_rgx,
682 "#{@center_begin}\\\n\\href{#{url}}{\\includegraphics*[width=#{width[ps]}pt]{#{dir.path.image_source_include_local}/#{image}}}#{caption} #{@center_end}")
683 when image_rgx
684 images_hash[ps].sub!(image_rgx,
685 "#{@center_begin}\\\n\\includegraphics*[width=#{width[ps]}pt]{#{dir.path.image_source_include_local}/#{image}}#{caption} #{@center_end}")
686 end
687 images_hash[ps]
688 elsif @md.fns =~/\.-ss[tm]$/ \
689 and FileTest.file?("#{dir.path.image_source_include_remote}/#{image}")
690 case images_hash[ps]
691 when url_image_rgx
692 images_hash[ps].sub!(url_image_rgx,
693 "#{@center_begin}\\\n\\href{#{url}}{\\includegraphics*[width=#{width[ps]}pt]{#{dir.path.image_source_include_remote}/#{image}}}#{caption}#{@center_end}")
694 when image_rgx
695 images_hash[ps].sub!(image_rgx,
696 "#{@center_begin}\\\n\\includegraphics*[width=#{width[ps]}pt]{#{dir.path.image_source_include_remote}/#{image}}#{caption}#{@center_end}")
697 end
698 images_hash[ps]
699 else
700 SiSU_Screen::Ansi.new(
701 @md.opt.act[:color_state][:set],
702 "ERROR - image:",
703 %{"#{image}" missing},
704 "search locations: #{dir.path.image_source_include_local}, #{dir.path.image_source_include_remote} and #{dir.path.image_source_include}"
705 ).error2 unless @md.opt.act[:quiet][:set]==:on
706 if images_hash[ps] =~url_image_rgx \
707 or images_hash[ps] =~image_rgx
708 images_hash[ps]=''
709 end
710 images_hash[ps]
711 end
712 else
713 link=z.strip #[/(.+?)\\/m,1]
714 images_hash[ps]="\\href{#{url}}{#{link}}#{punctuate}" if images_hash[ps] =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/
715 images_hash[ps]
716 end
717 else images_hash[ps]
718 end
719 images_hash[ps] #=ocn_display(dob) + images_hash[ps]
720 end #while loop
721 images_hash
722 end
723 use_images_hash={}
724 images_hash.each do |k,t|
725 use_images_hash[k]={ l: t, p: t}
726 end
727 dob.tmp=use_images_hash
728 dob
729 end
730 def title
731 title=SiSU_TeX_Pdf::SpecialCharacters.new(@md,@md.title.full).special_characters_safe
732 "\n\\title{#{title}}"
733 end
734 def title_landscape
735 title
736 end
737 def title_portrait
738 title
739 end
740 end
741 class FormatHead
742 require_relative 'prog_text_translation' # prog_text_translation.rb
743 def initialize(md,t_o)
744 @md,@t_o=md,t_o
745 @env=SiSU_Env::InfoEnv.new(@md.fns)
746 if t_o.is_a?(Hash)
747 @txt =t_o[:txt] || nil
748 @subtitle=t_o[:subtitle] || nil
749 @ps=t_o[:paper_size] || nil
750 @ocn=t_o[:ocn] || nil
751 @layout=t_o[:orientation] || nil
752 else
753 p t_o.class
754 p caller
755 end
756 @tx=SiSU_Env::GetInit.new.tex
757 @tex2pdf=@@tex3pdf ||=SiSU_Env::SystemCall.new.tex2pdf_engine
758 @ps=@txt if @txt=~/(?:a4|letter|legal|book|a5|b5)/i
759 @lang ||=SiSU_i18n::Languages.new #.list[@md.opt.lng][:xlp]
760 @author=if defined? @md.creator.author \
761 and @md.creator.author=~/\S+/
762 SiSU_TeX_Pdf::SpecialCharacters.new(@md,@md.creator.author).special_characters_safe
763 else ''
764 end
765 @subject=if defined? @md.classify.subject \
766 and @md.classify.subject=~/\S+/
767 SiSU_TeX_Pdf::SpecialCharacters.new(@md,@md.classify.subject).special_characters_safe
768 else ''
769 end
770 @keywords=if defined? @md.classify.keywords \
771 and @md.classify.keywords=~/\S+/
772 SiSU_TeX_Pdf::SpecialCharacters.new(@md,@md.classify.keywords).special_characters_safe
773 else ''
774 end
775 end
776 def tex_head_lang #babel 18n
777 lang_char_arr=@md.i18n
778 mainlang_char=if @md.i18n == Array \
779 and @md.i18n.length > 0
780 lang_char_arr.slice(0)
781 else @md.opt.lng
782 end
783 mainlang=@lang.list[mainlang_char][:xlp]
784 otherlang=if mainlang != 'english'
785 [ @lang.list['en'][:xlp] ]
786 else []
787 end
788 if lang_char_arr.length > 0
789 lang_char_arr.slice(1..9).each { |ch| otherlang << @lang.list[ch][:xlp] }
790 otherlang=otherlang.uniq
791 end
792 otherlang=otherlang.join(',')
793 { mainlang: mainlang, otherlang: otherlang }
794 end
795 def tex_head_encode
796 texpdf_fontface=if defined? @md.make.texpdf_fontface.main \
797 and not @md.make.texpdf_fontface.main.nil? \
798 and @md.make.texpdf_fontface.main=~/\S{3,}/
799 @md.make.texpdf_fontface.main
800 else @env.font.texpdf.main
801 end
802 texpdf_fontface_sans=if defined? @md.make.texpdf_fontface.sans \
803 and not @md.make.texpdf_fontface.sans.nil? \
804 and @md.make.texpdf_fontface.sans=~/\S{3,}/ # not used
805 @md.make.texpdf_fontface.sans
806 else @env.font.texpdf.sans
807 end
808 texpdf_fontface_serif=if defined? @md.make.texpdf_fontface.serif \
809 and not @md.make.texpdf_fontface.serif.nil? \
810 and @md.make.texpdf_fontface.serif=~/\S{3,}/ # not used
811 @md.make.texpdf_fontface.serif
812 else @env.font.texpdf.serif
813 end
814 texpdf_fontface_mono=if defined? @md.make.texpdf_fontface.mono \
815 and not @md.make.texpdf_fontface.mono.nil? \
816 and @md.make.texpdf_fontface.mono=~/\S{3,}/
817 @md.make.texpdf_fontface.mono
818 else @env.font.texpdf.mono
819 end
820 texpdf_fontface_cjk=if @md.opt.lng =~/zh/ \
821 and defined? @md.make.texpdf_fontface.cjk_zh \
822 and not @md.make.texpdf_fontface.cjk_zh.nil? \
823 and @md.make.texpdf_fontface.cjk_zh=~/\S{3,}/
824 @md.make.texpdf_fontface.cjk_zh
825 elsif @md.opt.lng =~/ja/ \
826 and defined? @md.make.texpdf_fontface.cjk_ja \
827 and not @md.make.texpdf_fontface.cjk_ja.nil? \
828 and @md.make.texpdf_fontface.cjk_ja=~/\S{3,}/
829 @md.make.texpdf_fontface.cjk_ja
830 elsif @md.opt.lng =~/ko/ \
831 and defined? @md.make.texpdf_fontface.cjk_ko \
832 and not @md.make.texpdf_fontface.cjk_ko.nil? \
833 and @md.make.texpdf_fontface.cjk_ko=~/\S{3,}/
834 @md.make.texpdf_fontface.cjk_ko
835 elsif @md.opt.lng =~/(?:zh|ja|ko)/ \
836 and defined? @md.make.texpdf_fontface.cjk \
837 and not @md.make.texpdf_fontface.cjk.nil? \
838 and @md.make.texpdf_fontface.cjk=~/\S{3,}/
839 @md.make.texpdf_fontface.cjk
840 else
841 case @md.opt.lng
842 when /zh/ then @env.font.texpdf.cjk_zh
843 when /ja/ then @env.font.texpdf.cjk_ja
844 when /ko/ then @env.font.texpdf.cjk_ko
845 else @env.font.texpdf.cjk
846 end
847 end
848 # you may wish to check selected font against available fonts:
849 # fc-list :outline -f "%{family}\n"
850 # fc-list :lang=ja
851 case @tex2pdf
852 when /xe/
853 if @md.opt.lng =~/(?:zh|ja|ko)/
854 <<-WOK
855 \\usepackage{ucs, fontspec, xltxtra, xunicode, xeCJK}
856 \\setmainCJKlanguage{#{tex_head_lang[:mainlang]}}
857 \\setCJKmainfont{#{texpdf_fontface_cjk}}
858 \\XeTeXlinebreaklocale "#{tex_head_lang[:mainlang]}"
859 \\XeTeXlinebreakskip = 0pt plus 1pt
860 \\setotherlanguage{#{tex_head_lang[:otherlang]}}
861 \\setmainfont{#{texpdf_fontface}}
862 \\setmonofont[Scale=0.85]{#{texpdf_fontface_mono}}
863 WOK
864 else
865 <<-WOK
866 \\usepackage{polyglossia, ucs, fontspec, xltxtra, xunicode}
867 \\setmainlanguage{#{tex_head_lang[:mainlang]}}
868 \\setotherlanguage{#{tex_head_lang[:otherlang]}}
869 \\setmainfont{#{texpdf_fontface}}
870 \\setmonofont[Scale=0.85]{#{texpdf_fontface_mono}}
871 % \\setsansfont{#{texpdf_fontface_sans}}
872 % \\setromanfont{#{texpdf_fontface_serif}}
873 WOK
874 end
875 when /pdf/
876 if @md.file_encoding =~ /iso-?8859/i #% iso8859
877 <<-WOK
878 % \\usepackage[latin1]{inputenc}
879 \\usepackage{fontspec}
880 WOK
881 else #% utf-8 assumed
882 <<-WOK
883 \\usepackage{babel}
884 \\usepackage{ucs}
885 \\usepackage[utf8x]{inputenc}
886 WOK
887 end
888 end
889 end
890 def tex_head_info
891 generator="Generated by: #{@md.project_details.project} #{@md.project_details.version} of #{@md.project_details.date_stamp} (#{@md.project_details.date})" if @md.project_details.version
892 lastdone="Last Generated on: #{Time.now}"
893 rubyv="Ruby version: #{@md.ruby_version}"
894 <<-WOK
895 %% SiSU (Linux & Ruby - \"better ways\") LaTeX output
896 %% #{generator}
897 %% #{rubyv}
898 %% LaTeX output
899 %% #{lastdone}
900 %% SiSU http://www.jus.uio.no/sisu
901 WOK
902 end
903 def tex_head_paper_portrait(d)
904 multicol=(@md.book_idx ? '\usepackage{multicol}' : '')
905 <<-WOK
906 #{tex_head_info}
907 \\documentclass[#{d[:fontsize]},#{d[:papertype]},titlepage]{scrartcl} %with titlepage
908 \\setlength{\\textheight}{#{d[:textheight]}mm} \\setlength{\\textwidth}{#{d[:textwidth]}mm}
909 \\setlength{\\oddsidemargin}{#{d[:oddsidemargin]}} \\setlength{\\evensidemargin}{#{d[:evensidemargin]}}
910 \\setlength{\\topmargin}{#{d[:topmargin]}} \\setlength{\\headheight}{#{d[:headheight]}}
911 \\setlength{\\headsep}{#{d[:headsep]}}
912 \\setlength{\\marginparsep}{#{d[:marginparsep]}}
913 \\setlength{\\marginparwidth}{#{d[:marginparwidth]}}
914 #{multicol}
915 WOK
916 end
917 def tex_head_paper_landscape(d)
918 <<-WOK
919 #{tex_head_info}
920 \\documentclass[#{d[:fontsize]},#{d[:papertype]},landscape,titlepage,twocolumn]{scrartcl} %with titlepage
921 \\setlength{\\textheight}{#{d[:textheight]}mm} \\setlength{\\textwidth}{#{d[:textwidth]}mm}
922 \\setlength{\\oddsidemargin}{#{d[:oddsidemargin]}} \\setlength{\\evensidemargin}{#{d[:evensidemargin]}}
923 \\setlength{\\topmargin}{#{d[:topmargin]}} \\setlength{\\headheight}{#{d[:headheight]}}
924 \\setlength{\\headsep}{#{d[:headsep]}}
925 \\setlength{\\columnsep}{#{d[:columnsep]}}
926 \\setlength{\\marginparsep}{#{d[:marginparsep]}}
927 \\setlength{\\marginparwidth}{#{d[:marginparwidth]}}
928 WOK
929 end
930 def tex_head_paper_portrait_dvi(d)
931 <<-WOK
932 #{tex_head_info}
933 \\documentclass[#{d[:fontsize]},#{d[:papertype]},titlepage]{scrartcl} %with titlepage
934 \\setlength{\\textheight}{#{d[:textheight]}mm} \\setlength{\\textwidth}{#{d[:textwidth]}mm}
935 \\setlength{\\oddsidemargin}{#{d[:oddsidemargin]}} \\setlength{\\evensidemargin}{#{d[:evensidemargin]}}
936 \\setlength{\\topmargin}{#{d[:topmargin]}} \\setlength{\\headheight}{#{d[:headheight]}}
937 \\setlength{\\headsep}{#{d[:headsep]}}
938 \\setlength{\\marginparsep}{#{d[:marginparsep]}}
939 \\setlength{\\marginparwidth}{#{d[:marginparwidth]}}
940 WOK
941 end
942 def tex_head_paper_dimensions
943 d={}
944 fontsize_set=if defined? @env.font.texpdf.size(@md.opt.act[:pdf_font_size]) \
945 and not @env.font.texpdf.size(@md.opt.act[:pdf_font_size]).nil?
946 @env.font.texpdf.size(@md.opt.act[:pdf_font_size])
947 else :na
948 end
949 case @layout
950 when :portrait
951 fontsize=(fontsize_set==:na) ? '11pt' : (fontsize_set + 'pt')
952 d[:papertype],d[:fontsize]='a4paper',fontsize
953 d[:oddsidemargin],d[:evensidemargin],d[:topmargin]='0mm','0mm','-12pt'
954 d[:headheight],d[:headsep],d[:columnsep]='12pt','35pt',''
955 d[:marginparsep],d[:marginparwidth]='4mm','8mm'
956 case @ps #@md.papersize
957 when /a4/i #European default, SiSU default
958 fontsize=(fontsize_set==:na) ? '12pt' : (fontsize_set + 'pt')
959 d[:papertype],d[:fontsize]='a4paper',fontsize
960 d[:textheight],d[:textwidth]=@tx.a4.portrait.h,@tx.a4.portrait.w
961 when /letter/i #U.S. default
962 fontsize=(fontsize_set==:na) ? '12pt' : (fontsize_set + 'pt')
963 d[:papertype],d[:fontsize]='letterpaper',fontsize
964 d[:textheight],d[:textwidth]=@tx.letter.portrait.h,@tx.letter.portrait.w
965 when /legal/i #U.S. alternative
966 fontsize=(fontsize_set==:na) ? '12pt' : (fontsize_set + 'pt')
967 d[:papertype],d[:fontsize]='legalpaper',fontsize
968 d[:textheight],d[:textwidth]=@tx.legal.portrait.h,@tx.legal.portrait.w
969 when /book|b5/i #book default - larger
970 fontsize=(fontsize_set==:na) ? '11pt' : (fontsize_set + 'pt')
971 d[:papertype],d[:fontsize]='b5paper',fontsize
972 d[:oddsidemargin],d[:evensidemargin],d[:topmargin]='-4mm','-4mm','-36pt'
973 d[:headheight],d[:headsep],d[:columnsep]='12pt','20pt',''
974 d[:textheight],d[:textwidth]=@tx.b5.portrait.h,@tx.b5.portrait.w
975 when /a5/i
976 fontsize=(fontsize_set==:na) ? '11pt' : (fontsize_set + 'pt')
977 d[:papertype],d[:fontsize]='a5paper',fontsize
978 d[:oddsidemargin],d[:evensidemargin],d[:topmargin]='-4mm','-4mm','-36pt'
979 d[:headheight],d[:headsep],d[:columnsep]='11pt','12pt',''
980 d[:marginparsep],d[:marginparwidth]='4mm','6mm'
981 d[:textheight],d[:textwidth]=@tx.a5.portrait.h,@tx.a5.portrait.w
982 else #default currently A4
983 fontsize=(fontsize_set==:na) ? '12pt' : (fontsize_set + 'pt')
984 d[:papertype],d[:fontsize]='a4paper',fontsize
985 d[:textheight],d[:textwidth]=@tx.a4.portrait.h,@tx.a4.portrait.w
986 end
987 when :landscape
988 fontsize=(fontsize_set==:na) ? '11pt' : (fontsize_set + 'pt')
989 d[:papertype],d[:fontsize]='a4paper',fontsize
990 d[:oddsidemargin],d[:evensidemargin],d[:topmargin]='6mm','6mm','-12mm'
991 d[:headheight],d[:headsep],d[:columnsep]='12pt','20pt','40pt'
992 d[:marginparsep],d[:marginparwidth]='4mm','8mm'
993 case @ps #@md.papersize
994 when /a4/i #European default, SiSU default
995 fontsize=(fontsize_set==:na) ? '11pt' : (fontsize_set + 'pt')
996 d[:papertype],d[:fontsize]='a4paper',fontsize
997 d[:textheight],d[:textwidth]=@tx.a4.landscape.h,@tx.a4.landscape.w
998 when /letter/i #U.S. default
999 fontsize=(fontsize_set==:na) ? '11pt' : (fontsize_set + 'pt')
1000 d[:papertype],d[:fontsize]='letterpaper',fontsize
1001 d[:textheight],d[:textwidth]=@tx.letter.landscape.h,@tx.letter.landscape.w
1002 when /legal/i #U.S. alternative
1003 fontsize=(fontsize_set==:na) ? '11pt' : (fontsize_set + 'pt')
1004 d[:papertype],d[:fontsize],d[:columnsep]='legalpaper',fontsize,'48pt'
1005 d[:textheight],d[:textwidth]=@tx.legal.landscape.h,@tx.legal.landscape.w
1006 when /book|b5/i #book default - larger
1007 fontsize=(fontsize_set==:na) ? '11pt' : (fontsize_set + 'pt')
1008 d[:papertype],d[:fontsize],d[:columnsep]='b5paper',fontsize,'35pt'
1009 d[:textheight],d[:textwidth]=@tx.b5.landscape.h,@tx.b5.landscape.w
1010 when /a5/i
1011 fontsize=(fontsize_set==:na) ? '10pt' : (fontsize_set + 'pt')
1012 d[:papertype],d[:fontsize],d[:columnsep]='a5paper',fontsize,'32pt'
1013 d[:textheight],d[:textwidth]=@tx.a5.landscape.h,@tx.a5.landscape.w
1014 else #default currently A4
1015 fontsize=(fontsize_set==:na) ? '12pt' : (fontsize_set + 'pt')
1016 d[:papertype],d[:fontsize]='a4paper',fontsize
1017 d[:textheight],d[:textwidth]=@tx.a4.landscape.h,@tx.a4.landscape.w
1018 end
1019 end
1020 d
1021 end
1022 def tex_head_paper
1023 case @layout
1024 when :portrait
1025 tex_head_paper_portrait(tex_head_paper_dimensions)
1026 when :landscape
1027 tex_head_paper_landscape(tex_head_paper_dimensions)
1028 end
1029 end
1030 def hyperlinks_monochrome
1031 <<-WOK
1032 colorlinks=true,
1033 urlcolor=myblack,
1034 filecolor=myblack,
1035 linkcolor=myblack,
1036 WOK
1037 end
1038 def hyperlinks_colored
1039 <<-WOK
1040 colorlinks=true,
1041 urlcolor=myblue, % \\href{...}{...} external url
1042 filecolor=mygreen, % \\href{...} local file
1043 linkcolor=myred, % \\href{...} and \\pageref{...}
1044 WOK
1045 end
1046 def hyperlinks_color?
1047 case @layout
1048 when :portrait then hyperlinks_monochrome
1049 if @env.texpdf_hyperlinks(@md.opt.act[:pdf_hyperlink_colors]).portrait != :na
1050 case @env.texpdf_hyperlinks(@md.opt.act[:pdf_hyperlink_colors]).portrait
1051 when :color then hyperlinks_colored
1052 when :mono then hyperlinks_monochrome
1053 else p __LINE__.to_s + ':error'
1054 end
1055 else hyperlinks_monochrome
1056 end
1057 when :landscape
1058 if @env.texpdf_hyperlinks(@md.opt.act[:pdf_hyperlink_colors]).landscape != :na
1059 case @env.texpdf_hyperlinks(@md.opt.act[:pdf_hyperlink_colors]).landscape
1060 when :color then hyperlinks_colored
1061 when :mono then hyperlinks_monochrome
1062 else p __LINE__.to_s + ':error'
1063 end
1064 else hyperlinks_colored
1065 end
1066 end
1067 end
1068 def tex_head_pdftex
1069 author=if defined? @md.creator.author \
1070 and @md.creator.author=~/\S+/
1071 SiSU_TeX_Pdf::SpecialCharacters.new(@md,@md.creator.author).special_characters_safe_no_urls
1072 else ''
1073 end
1074 <<-WOK
1075 \\usepackage{alltt}
1076 \\usepackage{thumbpdf}
1077 \\usepackage[#{@tex2pdf},
1078 #{hyperlinks_color?.strip}
1079 pdftitle={#{@txt}},
1080 pdfauthor={#{author}},
1081 pdfsubject={#{@subject}},
1082 pdfkeywords={#{@keywords}},
1083 pageanchor=true,
1084 plainpages=true,
1085 pdfpagelabels=true,
1086 pagebackref,
1087 bookmarks=true,
1088 bookmarksopen=true,
1089 pdfmenubar=true,
1090 pdfpagemode=UseOutline,
1091 pdffitwindow=true,
1092 pdfwindowui=true,
1093 plainpages=false,
1094 % pdfusetitle=true,
1095 % pdfpagelayout=SinglePage,
1096 % pdfpagelayout=TwoColumnRight,
1097 % pdfpagelayout=TwoColumnLeft,
1098 % pdfstartpage=3,
1099 pdfstartview=FitH
1100 ]
1101 {hyperref}
1102 %% trace lost characters
1103 % \\tracinglostchars = 1
1104 % \\tracingonline = 1
1105 \\usepackage[usenames]{color}
1106 \\definecolor{myblack}{rgb}{0,0,0}
1107 \\definecolor{myred}{rgb}{0.75,0,0}
1108 \\definecolor{mygreen}{rgb}{0,0.5,0}
1109 \\definecolor{myblue}{rgb}{0,0,0.5}
1110 \\definecolor{mywhite}{rgb}{1,1,1}
1111 \\usepackage{url}
1112 \\urlstyle{sf}
1113 %\\usepackage{breakurl}
1114 WOK
1115 end
1116 def tex_head_codeblock(codeblock_box_type)
1117 codeblock_box=if codeblock_box_type=='listings'
1118 <<-WOK
1119 \\usepackage{listings}
1120 \\usepackage{color}
1121 \\usepackage{textcomp}
1122 WOK
1123 elsif codeblock_box_type=='boites'
1124 "\\usepackage{boites}"
1125 else
1126 "\\usepackage{boites}"
1127 end
1128 codeblock_box
1129 end
1130 def tex_head_misc
1131 <<-WOK
1132 \\usepackage{textcomp}
1133 \\usepackage[parfill]{parskip}
1134 \\usepackage[normalem]{ulem}
1135 \\usepackage{soul}
1136 \\usepackage{longtable}
1137 \\usepackage[tc]{titlepic}
1138 \\usepackage{graphicx}
1139 \\makeatletter
1140 \\parindent0pt
1141 %\\usepackage{mathptmx}
1142 \\usepackage{amssymb}
1143 % amssymb used for backslash
1144 WOK
1145 end
1146 def document_head_with_orientation(codeblock_box_type)
1147 endnotes=("\\usepackage{endnotes}" if @txt =~/endnotes?/) || '' #not implemented see also def endnotes
1148 @lang.list[@md.i18n[0]][:xlp]
1149 <<-WOK
1150 #{tex_head_paper}
1151 #{tex_head_encode}
1152 #{tex_head_pdftex}
1153 #{tex_head_misc}
1154 #{tex_head_codeblock(codeblock_box_type)}
1155 \\setcounter{secnumdepth}{2}
1156 \\setcounter{tocdepth}{4}
1157 \\makeatletter
1158 #{endnotes}
1159 \\usepackage[multiple,ragged]{footmisc}
1160 \\setlength\\footnotemargin{12pt}
1161 \\usepackage[para]{manyfoot}
1162 \\DeclareNewFootnote{A}
1163 %\\DeclareNewFootnote[para]{A}
1164 \\newenvironment{ParagraphIndent}[1]%
1165 {
1166 \\begin{list}{}{%
1167 \\setlength\\topsep{0pt}%
1168 \\addtolength{\\leftmargin}{#1}
1169 \\setlength\\parsep{0pt plus 1pt}%
1170 }
1171 \\item[]
1172 }
1173 {\\end{list}}
1174
1175 \\newenvironment{ParagraphHang}[2]%
1176 {
1177 \\begin{list}{}{%
1178 \\setlength\\topsep{0pt}%
1179 \\addtolength{\\leftmargin}{#1}
1180 \\itemindent=#2
1181 \\setlength\\parsep{0pt plus 1pt}%
1182 }
1183 \\item[]
1184 }
1185 {\\end{list}}
1186
1187 \\newenvironment{Bullet}[1]%
1188 {
1189 \\begin{list}{}{%
1190 \\setlength\\topsep{0pt}%
1191 \\addtolength{\\leftmargin}{#1}
1192 \\itemindent=-1em
1193 \\setlength\\parsep{0pt plus 1pt}%
1194 }
1195 \\item[]
1196 }
1197 {\\end{list}}
1198 \\usepackage{fancyhdr}
1199 \\lhead{}
1200 \\renewcommand{\\part}{\\\@startsection
1201 {part}{1}{-2mm}%
1202 {-\\baselineskip}{0.5\\baselineskip}%
1203 {\\bfseries\\large\\upshape\\raggedright}}
1204 \\renewcommand{\\section}{\\\@startsection
1205 {section}{2}{-2mm}%
1206 {-\\baselineskip}{0.5\\baselineskip}%
1207 {\\bfseries\\large\\upshape\\raggedright}}
1208 \\renewcommand{\\subsection}{\\\@startsection
1209 {subsection}{3}{-2mm}%
1210 {-\\baselineskip}{0.5\\baselineskip}%
1211 {\\bfseries\\large\\upshape\\raggedright}}
1212 \\renewcommand{\\subsubsection}{\\\@startsection
1213 {subsubsection}{4}{-2mm}%
1214 {-\\baselineskip}{0.5\\baselineskip}%
1215 {\\normalfont\\normalsize\\bfseries\\raggedright}}
1216 \\renewcommand{\\paragraph}{\\\@startsection
1217 {paragraph}{5}{-2mm}%
1218 {-\\baselineskip}{0.5\\baselineskip}%
1219 {\\normalfont\\normalsize\\itshape\\raggedright}}
1220 \\renewcommand{\\subparagraph}{\\\@startsection
1221 {subparagraph}%{6}%{-2mm}%
1222 {-\\baselineskip}{0.5\\baselineskip}%
1223 {\\normalfont\\normalsize\\itshape\\raggedright}}
1224 % \\makeatother
1225 \\selectlanguage{#{@lang.list[@md.i18n[0]][:xlp]}}
1226 WOK
1227 end
1228 def a4generic
1229 end
1230 end
1231 class SpecialCharacters
1232 include SiSU_Parts_TeXpdf
1233 def initialize(md,str,is=:default)
1234 @md,@txt,@is=md,str,is
1235 @tex2pdf=@@tex3pdf ||=SiSU_Env::SystemCall.new.tex2pdf_engine
1236 end
1237 def xetex_code_listings(str,is=:default) # ~ ^ $ & % _ { } #LaTeX special characters - KEEP list
1238 word=str.scan(/\S+|\n/) #unless line =~/^(?:@\S|%+\s)/
1239 para_array=[]
1240 str=if word
1241 word.each do |w| # _ - / # | : ! ^ ~
1242 w=w.gsub(/#{Mx[:gl_o]}#lt#{Mx[:gl_c]}/,'<').gsub(/#{Mx[:gl_o]}#gt#{Mx[:gl_c]}/,'>').
1243 gsub(/[\\]?~/,'~').
1244 gsub(/[#{Mx[:br_line]}#{Mx[:br_paragraph]}]/,"\n"). #watch
1245 gsub(/#{Mx[:gl_o]}#(?:126|152)#{Mx[:gl_c]}/,'~'). #126 usual
1246 gsub(/\\?\||#{Mx[:gl_o]}#124#{Mx[:gl_c]}/,'|') #unless is=='code' #unless w=~/<~\d+;(?:[ohmu]|[0-6]:)\d+;\w\d+>/ # | SiSU not really special sisu character but done, also LaTeX
1247 para_array << w
1248 end
1249 str=para_array.join(' ')
1250 str=str.strip unless is==:code
1251 str
1252 else ''
1253 end
1254 str=str.gsub(/\s*#{Mx[:mk_o]}:name#\S+?#{Mx[:mk_c]}\s*/,' ').
1255 gsub(/.+?<-#>/,'').
1256 gsub(/#{Mx[:br_eof]}/,'').
1257 gsub(/#{Mx[:br_endnotes]}/,'').
1258 #problem sequence ->
1259 gsub(/&(?:lt|#060);/,'<'). # < SiSU special character also LaTeX
1260 gsub(/#{Mx[:gl_o]}#(?:gt|062)#{Mx[:gl_c]}/,'>'). # > SiSU special character also LaTeX
1261 gsub(/#{Mx[:gl_o]}#123#{Mx[:gl_c]}/,'{'). # { SiSU special character also LaTeX
1262 gsub(/#{Mx[:gl_o]}#125#{Mx[:gl_c]}/,'}'). # } SiSU special character also LaTeX
1263 gsub(/#{Mx[:gl_o]}#(?:126|152)#{Mx[:gl_c]}/,'~'). # ~ SiSU special character also LaTeX
1264 gsub(/#{Mx[:gl_o]}#035#{Mx[:gl_c]}/,'#'). # SiSU special character also LaTeX
1265 gsub(/#{Mx[:gl_o]}#033#{Mx[:gl_c]}/,'!'). # ! SiSU not really special sisu character but done, also LaTeX
1266 #gsub(/(^|\s)\*\s/,'\1\asterisk '). # * should you wish to escape astrisk e.g. describing \*{bold}*
1267 gsub(/#{Mx[:gl_o]}#042#{Mx[:gl_c]}/,'*'). # * should you wish to escape astrisk e.g. describing \*{bold}*
1268 gsub(/#{Mx[:gl_o]}#045#{Mx[:gl_c]}/,'-'). # - SiSU special character also LaTeX
1269 gsub(/#{Mx[:gl_o]}#043#{Mx[:gl_c]}/,'+'). # + SiSU special character also LaTeX
1270 gsub(/#{Mx[:gl_o]}#044#{Mx[:gl_c]}/,','). # + SiSU special character also LaTeX
1271 gsub(/#{Mx[:gl_o]}#038#{Mx[:gl_c]}/,'&'). #unless @txt=~/<:code>/ # / SiSU special character also LaTeX
1272 gsub(/#{Mx[:gl_o]}#047#{Mx[:gl_c]}/,'/'). # / SiSU special character also LaTeX
1273 gsub(/#{Mx[:gl_o]}#092#{Mx[:gl_c]}/,'\\'). # \ SiSU special character also LaTeX
1274 gsub(/#{Mx[:gl_o]}#095#{Mx[:gl_c]}/,'_'). # _ SiSU special character also LaTeX
1275 gsub(/#{Mx[:gl_o]}#124#{Mx[:gl_c]}/,'|'). # | SiSU not really special sisu character but done, also LaTeX
1276 gsub(/#{Mx[:gl_o]}#058#{Mx[:gl_c]}/,':'). # : SiSU not really special sisu character but done, also LaTeX
1277 gsub(/#{Mx[:gl_o]}#094#{Mx[:gl_c]}|\^/,'^'). # ^ SiSU not really special sisu character but done, also LaTeX
1278 ##watch placement, problem sequence ^
1279 gsub(/<sup><font face=symbol>&atild;<\/font><\/sup>/,' ').
1280 gsub(/\\copy(right|mark)?/,'<=copymark>') # ok problem with superscript
1281 end
1282 def xetex_special_characters_1(str,is=:default) # ~ ^ $ & % _ { } #LaTeX special characters - KEEP list
1283 word=str.scan(/\S+|\n/) #unless line =~/^(?:@\S|%+\s)/
1284 para_array=[]
1285 str=if word
1286 word.each do |w| # _ - / # | : ! ^ ~
1287 if w !~/https?:/ \
1288 and w=~/\/\S+?\// \
1289 and w.length > 6
1290 w=w.gsub(/([_.\/])/,'\1\-')
1291 end
1292 w=w.gsub(/#{Mx[:gl_o]}#lt#{Mx[:gl_c]}/,'<').gsub(/#{Mx[:gl_o]}#gt#{Mx[:gl_c]}/,'>').
1293 gsub(/[\\]?~/,'<=tilde>').
1294 gsub(/[#{Mx[:br_line]}#{Mx[:br_paragraph]}]/,' \newline '). #watch
1295 gsub(/#{Mx[:gl_o]}#(?:126|152)#{Mx[:gl_c]}/,'<=tilde>'). #126 usual
1296 gsub(/\\?\||#{Mx[:gl_o]}#124#{Mx[:gl_c]}/,'\pipe') #unless is=='code' #unless w=~/<~\d+;(?:[ohmu]|[0-6]:)\d+;\w\d+>/ # | SiSU not really special sisu character but done, also LaTeX
1297 if w !~/#{Mx[:rel_o]}/ \
1298 and w !~/#{Mx[:gl_o]}#/
1299 w=w.gsub(/\#/,'<=hash>')
1300 end
1301 para_array << w
1302 end
1303 str=para_array.join(' ')
1304 str=str.strip unless is==:code
1305 str
1306 else ''
1307 end
1308 str=str.gsub(/\s*#{Mx[:mk_o]}:name#\S+?#{Mx[:mk_c]}\s*/,' ').
1309 gsub(/.+?<-#>/,'').
1310 gsub(/#{Mx[:br_eof]}/,'').
1311 gsub(/#{Mx[:br_endnotes]}/,'')
1312 #problem sequence ->
1313 str=str.gsub(/&(?:nbsp);|#{Mx[:nbsp]}/,'\hardspace') unless is==:code # < SiSU special character also LaTeX
1314 str=str.gsub(/&(?:lt|#060);/,'\lt'). # < SiSU special character also LaTeX
1315 gsub(/#{Mx[:gl_o]}#(?:gt|062)#{Mx[:gl_c]}/,'\gt'). # > SiSU special character also LaTeX
1316 gsub(/#{Mx[:gl_o]}#123#{Mx[:gl_c]}/,'\curlyopen'). # { SiSU special character also LaTeX
1317 gsub(/#{Mx[:gl_o]}#125#{Mx[:gl_c]}/,'\curlyclose'). # } SiSU special character also LaTeX
1318 gsub(/#{Mx[:gl_o]}#(?:126|152)#{Mx[:gl_c]}/,'<=tilde>'). # ~ SiSU special character also LaTeX
1319 gsub(/#{Mx[:gl_o]}#035#{Mx[:gl_c]}/,'\#'). # # SiSU special character also LaTeX
1320 gsub(/#{Mx[:gl_o]}#033#{Mx[:gl_c]}/,'!'). # ! SiSU not really special sisu character but done, also LaTeX
1321 gsub(/(^|\s)\*\s/,'\1\asterisk '). # * should you wish to escape astrisk e.g. describing \*{bold}*
1322 gsub(/#{Mx[:gl_o]}#042#{Mx[:gl_c]}/,'\*'). # * should you wish to escape astrisk e.g. describing \*{bold}*
1323 gsub(/#{Mx[:gl_o]}#045#{Mx[:gl_c]}/,'-'). # - SiSU special character also LaTeX
1324 gsub(/#{Mx[:gl_o]}#043#{Mx[:gl_c]}/,'+'). # + SiSU special character also LaTeX
1325 gsub(/#{Mx[:gl_o]}#044#{Mx[:gl_c]}/,','). # + SiSU special character also LaTeX
1326 gsub(/#{Mx[:gl_o]}#038#{Mx[:gl_c]}/,'<=amp>'). #unless @txt=~/<:code>/ # / SiSU special character also LaTeX
1327 gsub(/#{Mx[:gl_o]}#047#{Mx[:gl_c]}/,'\slash'). # / SiSU special character also LaTeX
1328 gsub(/#{Mx[:gl_o]}#092#{Mx[:gl_c]}/,'\textbackslash'). # \ SiSU special character also LaTeX
1329 gsub(/#{Mx[:gl_o]}#095#{Mx[:gl_c]}/,'<=underscore>'). # _ SiSU special character also LaTeX
1330 gsub(/#{Mx[:gl_o]}#124#{Mx[:gl_c]}/,'|'). # | SiSU not really special sisu character but done, also LaTeX
1331 gsub(/#{Mx[:gl_o]}#058#{Mx[:gl_c]}/,':'). # : SiSU not really special sisu character but done, also LaTeX
1332 gsub(/#{Mx[:gl_o]}#094#{Mx[:gl_c]}|\^/,'\caret'). # ^ SiSU not really special sisu character but done, also LaTeX
1333 ##watch placement, problem sequence ^
1334 gsub(/<sup><font face=symbol>&atild;<\/font><\/sup>/,' ').
1335 gsub(/\\copy(right|mark)?/,'<=copymark>') # ok problem with superscript
1336 end
1337 def xetex_special_characters_2(str,is=:default)
1338 str=str.gsub(/#{Mx[:gl_o]}#156#{Mx[:gl_c]}/,'\oe ').
1339 gsub(/\$/,'\$').
1340 gsub(/\#/,'\#').
1341 gsub(/\%/,'\%').
1342 gsub(/\~/,'\~') #revist, should not be necessary to mark remaining tildes
1343 if str !~/^\s*#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}image\s/
1344 str=str.gsub(/_/,'\_')
1345 end
1346 str=str.gsub(/\{/,'\{').
1347 gsub(/\}/,'\}')
1348 str=if is==:code
1349 str.gsub(/&/,'{\\\&}').
1350 gsub(/\\~(\\\{)/,'{$\tilde$}\1').
1351 gsub(/(\\\})\\~/,'\1{$\tilde$}').
1352 gsub(/\\~(\[)/,'{$\tilde$}\1').
1353 gsub(/(\])\\~/,'\1{$\tilde$}').
1354 gsub(/<=tilde>/,'{$\tilde$}').
1355 gsub(/<=hash>/,'{\#}')
1356 else
1357 str.gsub(/&nbsp;|#{Mx[:nbsp]}/,'~'). # ~ character for hardspace
1358 gsub(/&/,'<=amp>')
1359 end
1360 str=str.gsub(/&\S+?;/,' ').
1361 gsub(/§/u,'\S'). #latex: space between next character not preserved? #str.gsub(/§ /,'\S ')
1362 gsub(/£/u,'\pounds').
1363 gsub(/<a href=".+?">/,' ').
1364 gsub(/<\/a>/,' ')
1365 unless is==:no_urls
1366 str=str.gsub(/((?:^|\s)#{Mx[:lnk_c]})#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,
1367 '\1\begin{scriptsize}\url{\2}\end{scriptsize}\3'). #special case \{ e.g. \}http://url
1368 gsub(/#{Mx[:url_o]}\\_(\S+?)#{Mx[:url_c]}/,
1369 '\begin{scriptsize}\url{\1}\end{scriptsize}'). #special case \{ e.g. \}http://url
1370 gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,
1371 '\begin{scriptsize}\\url{\1}\end{scriptsize}') #specially escaped url no decoration
1372 end
1373 if is !=:code \
1374 and is !=:no_urls
1375 str=str.gsub(/(^|#{Mx[:gl_c]}|\s)((?:https?|file|ftp):\/\/\S+?\.[^'"\s]+?)([;.,]?(?=\s|$))/,
1376 "\\1#{url_decoration.tex_open}\\begin{scriptsize}\\url{\\2}\\end{scriptsize}#{url_decoration.tex_close}\\3") #url matching with decoration <url> positive lookahead, sequence issue with { linked }http://url cannot use \b at start
1377 end
1378 str=str.gsub(/<:ee>/,'').
1379 gsub(/<!>/,' '). #proposed change, insert, but may be redundant
1380 gsub(/<(br|p)>|<\/\s*(br|p)>|<(br|p)\s*\/>/," #{Tex[:backslash]*2} "). # Work Area
1381 gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/,'\begin{bfseries}\1 \end{bfseries}').
1382 gsub(/<h\d+>(.+?)<\/h\d+>/,'\begin{bfseries}\1 \end{bfseries}').
1383 gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/,'\emph{\1}').
1384 gsub(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/,'\uline{\1}'). # ulem
1385 gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,"``\\1''"). # quote #CHECK
1386 gsub(/#{Mx[:fa_insert_o]}(.+?)#{Mx[:fa_insert_c]}/,'\uline{\1}'). # ulem
1387 gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/,'\sout{\1}'). # ulem
1388 gsub(/#{Mx[:fa_superscript_o]}(.+?)#{Mx[:fa_superscript_c]}/,"\$^{\\textrm{\\1}}\$").
1389 gsub(/#{Mx[:fa_subscript_o]}(.+?)#{Mx[:fa_subscript_c]}/,"\$_{\\textrm{\\1}}\$").
1390 gsub(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/,'\begin{monosp}\1\end{monosp}')
1391 unless is==:code
1392 str=str.gsub(/"(.+?)"/,'“\1”'). # quote marks / quotations open & close " need condition exclude for code
1393 gsub(/\s+"/,' “'). # open "
1394 gsub(/^(#{Mx[:lv_o]}[1-6-]:\S*?#{Mx[:lv_c]}|<.+?>)?\s*"/,'\1“'). #fix Mx[:lv_o] # open "
1395 gsub(/"(\s|\.|,|:|;)/,'”\1'). # close "
1396 gsub(/"(#{Mx[:lv_o]}[1-6-]:\S*?#{Mx[:lv_c]}|<.+?>)?\s*$/,'”\1'). #fix Mx[:lv_o] # close "
1397 gsub(/"(\.|,)/,'”'). # close "
1398 gsub(/\s+'/,' `'). # open '
1399 gsub(/^(#{Mx[:lv_o]}[1-6-]:\S*?#{Mx[:lv_c]}|<.+?>)?\s*'/,'\1`') #fix Mx[:lv_o] # open '
1400 end
1401 str=str.gsub(/(<font.*?>|<\/font>)/,'').
1402 gsub(/\s*#{Mx[:fa_superscript_o]}(\S+?)#{Mx[:fa_superscript_c]}/,'^\1')
1403 str
1404 end
1405 def xetex_special_characters_3(str)
1406 str=str.gsub(/<br(\s*[^\/][^>])/,'\1'). # clean up, incredibly messy :-( footnote indents, problems if match exists in ordinary paragraphs? check! Work Area 200501 a bit tricky as must be able to match multiple times, and to clean remainder
1407 gsub(/([^<][^b][^r]\s+)\/>/,'\1') # clean up, incredibly messy :-( footnote indents, problems if match exists in ordinary paragraphs? check! Work Area 200501 a bit tricky as must be able to match multiple times, and to clean remainder
1408 while str =~/(https?:\/\/\S+?)(?:<=tilde>\S+)+/ #tilde in urls \href treated differently from text #FIX
1409 str=str.gsub(/(https?:\/\/\S+?)(?:<=tilde>(\S+))+/,'\1~\2')
1410 end
1411 str=str.gsub(/<=tilde>/,'{$\tilde$}').
1412 gsub(/(https?:\/\/\S+?)(?:(?:<=hash>)(\S+))+/,'\1#\2'). #hash in urls \href treated differently from text #FIX
1413 gsub(/<=hash>/,'{\#}')
1414 while str =~/(https?:\/\/\S+?)(?:<=amp>\S+)+/ #amp in urls \href treated differently from text #FIX
1415 str=str.gsub(/(https?:\/\/\S+?)(?:<=amp>(\S+))+/,'\1&\2')
1416 end
1417 str=str.gsub(/<=amp>/,'{\\\&}'). #changed ... 2005
1418 gsub(/<=copymark>\s*(.+)/,
1419 '^\copyright \textnormal{\1} \2') # watch likely to be problematic
1420 str
1421 end
1422 def special_characters_safe_close(str)
1423 str=str.gsub(/<=tilde>/,'{$\tilde$}').
1424 gsub(/<=hash>/,'{\#}').
1425 gsub(/<=amp>/,'{\\\&}'). #changed ... 2005
1426 gsub(/<=copymark>\s*(.+)/,
1427 '^\copyright \textnormal{\1} \2') # watch likely to be problematic
1428 end
1429 def special_characters_code_fix(str)
1430 str=str.gsub(/<=tilde>/,'{$\tilde$}')
1431 str
1432 end
1433 def special_characters_unsafe_1(str) #depreciated, make obsolete
1434 # some substitutions are sequence sensitive, rearrange with care.
1435 str=str.gsub(/\\textbackslash (copyright|clearpage|newpage)/,"\\\\\\1") #kludge bad solution, find out where tail is sent through specChar !
1436 str
1437 end
1438 def special_characters # special characters - some substitutions are sequence sensitive, rearrange with care
1439 str,is=@txt,@is
1440 str=xetex_special_characters_1(str,is) unless str.nil?
1441 str=special_characters_unsafe_1(str) unless str.nil? #xetex_special_characters_unsafe_1(@txt)
1442 str=xetex_special_characters_2(str,is) unless str.nil? #issues with xetex
1443 str=xetex_special_characters_3(str) unless str.nil?
1444 @txt=str
1445 end
1446 def special_word_break_points
1447 str=@txt
1448 str=str.gsub(/([_,.;:\/|=])/,'\1\-').
1449 gsub(/(--)(\S{4,})/,'\1\-\2')
1450 @txt=str
1451 end
1452 def special_number_break_points
1453 str=@txt
1454 str=str.gsub(/([0-9a-f]{8})/i,'\1\-')
1455 @txt=str
1456 end
1457 def special_characters_safe # special characters - some substitutions are sequence sensitive, rearrange with care
1458 str,is=@txt,@is
1459 str=xetex_special_characters_1(str,is) unless str.nil?
1460 str=xetex_special_characters_2(str,is) unless str.nil? # remove this to start with, causes issues
1461 str=special_characters_safe_close(str) unless str.nil?
1462 @txt=str
1463 end
1464 def special_characters_safe_no_urls
1465 str,is=@txt,:no_urls
1466 str=xetex_special_characters_1(str,is) unless str.nil?
1467 str=xetex_special_characters_2(str,is) unless str.nil? # remove this to start with, causes issues
1468 str=special_characters_safe_close(str) unless str.nil?
1469 @txt=str
1470 end
1471 def characters_code_listings # special characters - some substitutions are sequence sensitive, rearrange with care
1472 str,is=@txt,@is
1473 str=xetex_code_listings(str,is) unless str.nil?
1474 @txt=str
1475 end
1476 def special_characters_code
1477 str=@txt
1478 str=str.gsub(/ \\\\([ #{Mx[:br_nl]}]+|$)/,' \textbackslash\textbackslash\hardspace\1')
1479 str
1480 end
1481 end
1482 class UseTeX
1483 include SiSU_Parts_TeXpdf
1484 attr_accessor :url,:txt,:date
1485 def initialize(md)
1486 @md=md
1487 @date=SiSU_Env::InfoDate.new # #{@date.year}
1488 @copymark='{\\begin{footnotesize}\\raisebox{1ex}{\\copyright}\\end{footnotesize}}'
1489 end
1490 def skip
1491 "\n\\vspace*{\\smallskipamount} \n"
1492 end
1493 def paraskip_normal
1494 '\setlength{\parskip}{1ex plus0.5ex minus0.2ex}'
1495 end
1496 def paraskip_small
1497 '\setlength{\parskip}{0.5ex plus0.2ex minus0.1ex}'
1498 end
1499 def paraskip_tiny
1500 '\setlength{\parskip}{0.1ex plus0.1ex minus0.1ex}'
1501 end
1502 def skip_small
1503 "\\smallskip{}"
1504 end
1505 def skip_small_vspace
1506 "\n\\vspace*{\\smallskipamount} \n"
1507 end
1508 def skip_small_footnote
1509 end
1510 def skip_medium
1511 "\n\\medskip{}\n\n"
1512 end
1513 def skip_dummy
1514 "\n"
1515 end
1516 def header
1517 "\\lhead[ ]{ }\n" +
1518 "\\chead[ \\fancyplain{} \\bfseries \\footnotesize \\leftmark ]{ \\fancyplain{} \\bfseries \\footnotesize \\rightmark }\n" +
1519 "\\rhead[ ]{ }\n"
1520 end
1521 def footer
1522 "\\lfoot[\\textrm{\\thepage}]{\\tiny \\href{#{@md.footer_links[:left][:url]}}{#{@md.footer_links[:left][:say]}}}\n" +
1523 "\\cfoot{\\href{#{@md.footer_links[:center][:url]}}{#{@md.footer_links[:center][:say]}}}\n" +
1524 "\\rfoot[\\tiny \\href{}{}]{\\textrm{\\thepage}}\n"
1525 end
1526 def site
1527 if not the_url.home.empty? \
1528 and not the_url.home_txt.empty?
1529 "\n\\date{\\begin{tiny} \\end{tiny}}"
1530 else ''
1531 end
1532 end
1533 def owner_chapter
1534 "Contact Details for Original Promulgating Authority"
1535 end
1536 #BOOK standard dimensions - 229x156
1537 def newpage(orientation)
1538 case orientation
1539 when :landscape # using longtable latex package
1540 <<-WOK
1541 \\clearpage
1542 WOK
1543 when :portrait
1544 <<-WOK
1545 \\newpage
1546 WOK
1547 end
1548 end
1549 def sisu_rights
1550 v=SiSU_Env::InfoVersion.instance.get_version
1551 base_prog_txt=if @md.base_program
1552 case @md.base_program
1553 when /kdissert/i then "\n\\\\ This document prepared using \\href{http://freehackers.org/~tnagy/kdissert/}{Kdissert \\ http://freehackers.org/~tnagy/kdissert/ } \\\\ Kdissert is Document Mapping software by Thomas Nagy"
1554 else ''
1555 end
1556 else ''
1557 end
1558 <<-WOK
1559 \\\\ ~
1560 {\\begin{footnotesize}#{base_prog_txt}
1561 \\\\ Generated by \\href{http://www.jus.uio.no/sisu}{SiSU} \\begin{tiny}[ #{v.project} #{v.version} of #{v.date_stamp} ]\\end{tiny} \\href{http://www.jus.uio.no/sisu}{www.jus.uio.no/sisu}
1562 \\\\ Copyright #{@copymark} 1997, current #{@date.year_static} Ralph Amissah, All Rights Reserved.
1563 \\\\ SiSU is software for document structuring, publishing and search (with object citation numbering), \\href{http://www.sisudoc.org}{www.sisudoc.org}
1564 \\\\ SiSU is released under \\href{http://www.fsf.org/licenses/gpl.html}{GPL 3 } or later, #{url_brace.tex_open}\\href{http://www.fsf.org/licenses/gpl.html}{http://www.fsf.org/licenses/gpl.html}#{url_brace.tex_close}.
1565 {\\end{footnotesize}
1566 \\\\
1567 WOK
1568 end
1569 def doc_sc_info_footnote_full
1570 <<-WOK
1571 \\footnote{%\nGenerated by \\href{http://www.jus.uio.no/sisu}{SiSU \\ www.jus.uio.no/sisu }\\ \\newline \\scriptsize{Document version information: \\emph{sourcefile} \\uline{#{@md.fnstex}}; \\emph{version} \\uline{#{@md.sc_number}}; \\emph{date} \\uline{#{@md.sc_date}}; \\emph{time} \\uline{#{@md.sc_time}}}}
1572 WOK
1573 end
1574 def doc_sc_info_footnote_brief
1575 " \\footnote{%\nGenerated by \\href{http://www.jus.uio.no/sisu}{SiSU} \\ \\href{http://www.jus.uio.no/sisu}{www.jus.uio.no/sisu} \\newline \\href{http://www.sisudoc.org}{www.sisudoc.org} \\\n}"
1576 end
1577 def doc_sc_info
1578 v=SiSU_Env::InfoVersion.instance.get_version
1579 <<-WOK
1580 \\\\
1581 {\\begin{footnotesize}
1582 Document version information: \\\\
1583 \\emph{sourcefile} \\uline{#{@md.fnstex}}; \\emph{version} \\uline{#{@md.sc_number}}; \\emph{date} \\uline{#{@md.sc_date}}; \\emph{time} \\uline{#{@md.sc_time}} \\\\
1584 Generated by \\href{http://www.jus.uio.no/sisu}{SiSU www.jus.uio.no/sisu }\\- version information: \\\\
1585 \\uline{ #{v.project} #{v.version} of #{v.date_stamp}}
1586 \\end{footnotesize}}&
1587 WOK
1588 end
1589 def doc_no_sc_info
1590 v=SiSU_Env::InfoVersion.instance.get_version
1591 <<-WOK
1592 \\\\
1593 {\\begin{small}
1594 Document information: \\\\
1595 \\emph{sourcefile} \\uline{#{@md.fnstex}} \\\\
1596 Generated by \\href{http://www.jus.uio.no/sisu}{SiSU www.jus.uio.no/sisu } \\\\ version information: \\
1597 \\uline{ #{v.project} #{v.version} of #{v.date_stamp}}
1598
1599 \\end{small}}&
1600 WOK
1601 end
1602 def endnotes #not used should be inserted before MetaData section which preceeds doc_tail, but is "part of document"
1603 <<-WOK
1604 \\subsection*{Endnotes}
1605 \\addcontentsline{toc}{section}{Endnotes}
1606 \\
1607 \\listofendnotes
1608 WOK
1609 end
1610 end
1611 end
1612 __END__
1613 #ack usepackage texpdf*
1614 #ack usepackage texpdf* |ack '\{.+?\}'
1615 #see sisu_texpdf_usepackage.rb
1616 alltt.sty
1617 amssymb.sty
1618 babel.sty
1619 boites.sty
1620 color.sty
1621 endnotes.sty
1622 fancyhdr.sty
1623 fontspec.sty
1624 footmisc.sty
1625 graphicx.sty
1626 inputenc.sty
1627 listings.sty
1628 longtable.sty
1629 manyfoot.sty
1630 multicol.sty
1631 parskip.sty
1632 polyglossia.sty
1633 soul.sty
1634 textcomp.sty
1635 thumbpdf.sty
1636 titlepic.sty
1637 ucs.sty
1638 ulem.sty
1639 url.sty
1640 xetex.sty
1641 xltxtra.sty
1642 xunicode.sty
1643 ---
1644 texlive-latex-base
1645 texlive-base
1646 texlive-latex-extra
1647 texlive-latex-recommended
1648 texlive-xetex
1649 texlive-generic-recommended
1650 ---
1651 texlive-latex-base:
1652 /usr/share/texlive/texmf-dist/tex/generic/babel/babel.sty
1653 /usr/share/texlive/texmf-dist/tex/latex/base/alltt.sty
1654 /usr/share/texlive/texmf-dist/tex/latex/base/inputenc.sty
1655 /usr/share/texlive/texmf-dist/tex/latex/base/textcomp.sty
1656 /usr/share/texlive/texmf-dist/tex/latex/fancyhdr/fancyhdr.sty
1657 /usr/share/texlive/texmf-dist/tex/latex/graphics/color.sty
1658 /usr/share/texlive/texmf-dist/tex/latex/graphics/graphicx.sty
1659 /usr/share/texlive/texmf-dist/tex/latex/tools/longtable.sty
1660 /usr/share/texlive/texmf-dist/tex/latex/tools/multicol.sty
1661 ---
1662 texlive-base:
1663 /usr/share/texlive/texmf-dist/tex/latex/amsfonts/amssymb.sty
1664 ---
1665 texlive-latex-extra:
1666 /usr/share/texlive/texmf-dist/tex/latex/boites/boites.sty
1667 /usr/share/texlive/texmf-dist/tex/latex/endnotes/endnotes.sty
1668 /usr/share/texlive/texmf-dist/tex/latex/footmisc/footmisc.sty
1669 /usr/share/texlive/texmf-dist/tex/latex/ncctools/manyfoot.sty
1670 /usr/share/texlive/texmf-dist/tex/latex/soul/soul.sty
1671 /usr/share/texlive/texmf-dist/tex/latex/titlepic/titlepic.sty
1672 /usr/share/texlive/texmf-dist/tex/latex/ucs/ucs.sty
1673 ---
1674 texlive-latex-recommended:
1675 /usr/share/texlive/texmf-dist/tex/generic/thumbpdf/thumbpdf.sty
1676 /usr/share/texlive/texmf-dist/tex/latex/fontspec/fontspec.sty
1677 /usr/share/texlive/texmf-dist/tex/latex/listings/listings.sty
1678 /usr/share/texlive/texmf-dist/tex/latex/parskip/parskip.sty
1679 /usr/share/texlive/texmf-dist/tex/latex/url/url.sty
1680 ---
1681 texlive-xetex:
1682 /usr/share/texlive/texmf-dist/tex/latex/xltxtra/xltxtra.sty
1683 /usr/share/texlive/texmf-dist/tex/xelatex/polyglossia/polyglossia.sty
1684 /usr/share/texlive/texmf-dist/tex/xelatex/xunicode/xunicode.sty
1685 ---
1686 texlive-generic-recommended:
1687 /usr/share/texlive/texmf-dist/tex/generic/ulem/ulem.sty