texpdf, indent values, use formula (to replace table)
[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 _idt=10
322 indent = "#{_idt*(@dob.indent.to_i-1)}mm"
323 hang = "#{_idt*(@dob.hang.to_i - @dob.indent.to_i)}mm"
324 "\\begin{ParagraphHang}{#{indent}}{#{hang}}#{@dob.tmp} \\end{ParagraphHang}}"
325 end
326 def indent
327 indent=case @dob.indent
328 when /1/ then '0mm'
329 when /2/ then '10mm'
330 when /3/ then '20mm'
331 when /4/ then '30mm'
332 when /5/ then '40mm'
333 when /6/ then '50mm'
334 when /7/ then '60mm'
335 when /8/ then '70mm'
336 when /9/ then '80mm'
337 end
338 "\\begin{ParagraphIndent}{#{indent}}#{@dob.tmp} \\end{ParagraphIndent}}"
339 end
340 def bullet
341 blt=if @dob.indent
342 indent=case @dob.indent
343 when /1/ then '0em'
344 when /2/ then '1.0em'
345 when /3/ then '2.0em'
346 when /4/ then '3.0em'
347 when /5/ then '4.0em'
348 when /6/ then '5.0em'
349 when /7/ then '6.0em'
350 when /8/ then '7.0em'
351 when /9/ then '8.0em'
352 else '-1.0em'
353 end
354 "\\begin{Bullet}{#{indent}}$\\txtbullet$\\hspace{\\enspace}#{@dob.tmp}\\end{Bullet}"
355 else
356 "\\begin{Bullet}{-5mm}$\\txtbullet$\\hspace{\\enspace}#{@dob.tmp}\\end{Bullet}"
357 end
358 blt
359 end
360 def symbol_graphic
361 dir=SiSU_Env::InfoEnv.new(@md.fns)
362 image='c_' + /<:=\s*(\S+?)\s*>/m.match(@txt).captures.join + '.png' #watch
363 if FileTest.file?("#{dir.path.image_source_include}/#{image}")
364 @txt.gsub!(/<:=\s*(\S+?)\s*>/,
365 "\\includegraphics*[width=11pt]{#{dir.path.image_source_include}/c_\\1.png}")
366 else
367 SiSU_Screen::Ansi.new(
368 @md.opt.act[:color_state][:set],
369 "ERROR - image:",
370 %{"#{image}" missing},
371 "search path: #{dir.path.image_source_include}"
372 ).error2 unless @md.opt.act[:quiet][:set]==:on
373 @txt.gsub!(/#{Mx[:lnk_o]}\S+\.(png|jpg|gif).+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/,'') # fragile match operator\\ fragile !
374 end
375 end
376 def url_str_internal(str,idx=nil)
377 map_nametags=SiSU_Particulars::CombinedSingleton.instance.get_map_nametags(@md).nametags_map #p map_nametags
378 rgx_url_internal=/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:rel_o]}#?\S+?#{Mx[:rel_c]}/m
379 while str =~/#{Mx[:lnk_o]}([^#{Mx[:lnk_o]}#{Mx[:lnk_c]}]+)#{Mx[:lnk_c]}#{Mx[:rel_o]}:(\S+?)#{Mx[:rel_c]}/m
380 link,url=$1,$2
381 link,url=link.strip,url.strip
382 link.gsub!(/&/,"#{Xx[:protect]}&")
383 url="#{@env.url.root}/" + url
384 str.sub!(/#{Mx[:lnk_o]}[^#{Mx[:lnk_o]}#{Mx[:lnk_c]}]+#{Mx[:lnk_c]}#{Mx[:rel_o]}:\S+?#{Mx[:rel_c]}/m,
385 "#{url_decoration.tex_open}\\href{#{url}}{#{link}}#{url_decoration.tex_close}")
386 end
387 while str =~/#{Mx[:lnk_o]}([^#{Mx[:lnk_o]}#{Mx[:lnk_c]}]+)#{Mx[:lnk_c]}#{Mx[:rel_o]}#?(\S+?)#{Mx[:rel_c]}/m
388 link,url=$1,$2
389 link,url=link.strip,url.strip
390 link.gsub!(/&/,"#{Xx[:protect]}&")
391 url.gsub!(/\\_/,'_')
392 ocn_lnk=if map_nametags[url] \
393 and map_nametags[url][:ocn]
394 map_nametags[url][:ocn]
395 else nil
396 end
397 ocn_lnk=(url=~/^\d+$/ ? url : ocn_lnk)
398 if ocn_lnk and not ocn_lnk.empty?
399 idx \
400 ? (str.sub!(rgx_url_internal,"\\hyperlink{#{ocn_lnk}}{#{link}}"))
401 : (str.sub!(rgx_url_internal,"#{url_decoration.tex_open}\\hyperlink{#{ocn_lnk}}{#{link}}#{url_decoration.tex_close}"))
402 else
403 puts %{name tag: "#{url}" not found}
404 str.sub!(rgx_url_internal,"#{link}")
405 end
406 #[keep] code that follows uses nametags directly, currently nametags converted to their ocn, related code: |texpdf.rb|@|hypertargets|
407 #idx \
408 #? (str.sub!(rgx_url_internal,"\\hyperlink{#{url}}{#{link}}")) \
409 #: (str.sub!(rgx_url_internal,"#{url_decoration.tex_open}\\hyperlink{#{url}}{#{link}}#{url_decoration.tex_close}"))
410 end
411 str=str.gsub(/#{Xx[:protect]}/,'')
412 end
413 def url_str(str)
414 rgx_url_generic=/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/m
415 while str =~rgx_url_generic
416 if str=~rgx_url_generic
417 regx_url=%r/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/m
418 z,url=regx_url.match(str).captures if str =~regx_url
419 url=url.strip
420 link=z.strip
421 link.gsub!(/&/,"#{Xx[:protect]}&")
422 str.sub!(rgx_url_generic,"#{url_decoration.tex_open}\\href{#{url}}{#{link}}#{url_decoration.tex_close}")
423 str=str.gsub(/#{Xx[:protect]}/,'')
424 str
425 else str
426 end
427 str
428 end
429 str
430 end
431 def url_with_txt(dob)
432 rgx_url_generic=/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/m
433 while dob.tmp =~rgx_url_generic
434 if dob.tmp=~rgx_url_generic
435 if dob.tmp =~/#{Mx[:lnk_o]}(?:.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/m
436 regx_url=%r/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/m
437 punctuate=/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/m.match(dob.tmp).captures.join
438 else
439 regx_url=%r/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/m
440 punctuate=''
441 end
442 z,url=regx_url.match(dob.tmp).captures if dob.tmp =~regx_url
443 url=url.strip
444 link=z.strip
445 link.gsub!(/&/,"#{Xx[:protect]}&")
446 dob.tmp.sub!(rgx_url_generic,"#{url_decoration.tex_open}\\href{#{url}}{#{link}}#{url_decoration.tex_close}#{punctuate}")
447 dob.tmp.gsub!(/#{Xx[:protect]}/,'')
448 #dob.tmp=dob.tmp.sub(rgx_url_generic,"#{url_decoration.tex_open}\\href{#{url}}{#{link}}#{url_decoration.tex_close}#{punctuate}").
449 # gsub(/#{Xx[:protect]}/,'')
450 dob
451 else dob
452 end
453 dob
454 end
455 dob
456 end
457 def urls_txt_and_images
458 dob=@dob
459 dir=SiSU_Env::InfoEnv.new(@md.fns)
460 @dm={
461 'a4'=> @tx.a4.landscape.img_px,
462 'letter'=> @tx.letter.landscape.img_px,
463 'legal'=> @tx.legal.landscape.img_px,
464 'b5'=> @tx.b5.landscape.img_px,
465 'a5'=> @tx.a5.landscape.img_px
466 }
467 images_hash={ }
468 generic_rgx=/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image\b)/m
469 rgx_url_generic=/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/m
470 #url_bare_rgx=/#{Mx[:url_o]}\S+?#{Mx[:url_c]}/m
471 url_image_rgx=/#{Mx[:lnk_o]}[a-zA-Z0-9_\\-]+\.(?:png|jpg|gif).+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/m
472 image_rgx=/#{Mx[:lnk_o]}[a-zA-Z0-9_\\-]+\.(?:png|jpg|gif).+?#{Mx[:lnk_c]}image/m
473 @md.papersize_array.each do |ps|
474 images_hash[ps] = dob.tmp
475 while images_hash[ps] =~generic_rgx
476 if dob.tmp =~rgx_url_generic \
477 and dob.tmp !~/\.(?:png|jpg|gif)|#{Mx[:lnk_c]}image\b/m
478 dob=url_with_txt(dob)
479 elsif images_hash[ps]=~generic_rgx
480 if dob.tmp=~rgx_url_generic
481 if images_hash[ps] =~/#{Mx[:lnk_o]}(?:.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/m
482 regx_url=%r/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/m
483 punctuate=/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/m.match(images_hash[ps]).captures.join
484 else
485 regx_url=%r/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/m
486 punctuate=''
487 end
488 z,url=regx_url.match(images_hash[ps]).captures if images_hash[ps] =~regx_url
489 url=url.strip
490 else
491 if images_hash[ps] =~/#{Mx[:lnk_o]}(?:.+?)#{Mx[:lnk_c]}image\.[^'"\s]+?(?:[;.,]?(?:\s|$)|(?:\s|$))/m
492 regx_url=%r/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}image\.[^'"\s]+?(?:[;.,]?(?:\s|$)|(?:\s|$))/m
493 punctuate=/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}image\.[^'"\s]+?([;.,]?(?:\s|$))/m.match(images_hash[ps]).captures.join
494 else
495 regx_url=%r/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}image/m
496 punctuate=''
497 end
498 z=regx_url.match(images_hash[ps])[1] if images_hash[ps] =~regx_url
499 url=''
500 end
501 if images_hash[ps] =~/#{Mx[:lnk_o]}\s*\S+\.?(?:png|jpg|gif)/m \
502 and images_hash[ps]=~/\s+\d+x\d+(\s+|\s*#{Mx[:lnk_c]})/m
503 image=z.scan(/\S+/)[0] #image,x,y=z.scan(/\S+/)
504 image.gsub!(/\\/,'')
505 w=((z =~/\s(\d+)x\d*/) ? z[/\s(\d+)x\d*/,1] : 200)
506 width={}
507 width['a4'] = ((w.to_i > @dm['a4']) ? @dm['a4'] : w)
508 width['letter'] = ((w.to_i > @dm['letter']) ? @dm['letter'] : w)
509 width['legal'] = ((w.to_i > @dm['legal']) ? @dm['legal'] : w)
510 width['a5'] = ((w.to_i > @dm['a5']) ? @dm['a5'] : w)
511 width['b5'] = ((w.to_i > @dm['b5']) ? @dm['b5'] : w)
512 c=z[/``(.+?)''/m,1]
513 hsp="\n{\\color{mywhite} .}&~\n" # ~ character for hardspace
514 caption=(c ? "{\\\\\ \n\\begin{scriptsize}#{hsp*3}#{c}\\end{scriptsize}&}" : '')
515 elsif images_hash[ps] =~/#{Mx[:lnk_o]}\s*(\S+\.?\.(?:png|jpg|gif))/m
516 SiSU_Screen::Ansi.new(
517 @md.opt.act[:color_state][:set],
518 %{document built without image: "#{$1}" as image dimensions not provided (either image not found or neither imagemagick nor graphicsmagick is installed)?\n}
519 ).print_grey #unless @md.opt.act[:quiet][:set]==:on
520 images_hash[ps].gsub!(/#{Mx[:lnk_o]}\s*(\S+\.?\.(?:png|jpg|gif))/,'[image]')
521 end
522 if image #most images fc etc. #% clean up !
523 if FileTest.file?("#{dir.path.image_source_include}/#{image}")
524 case images_hash[ps]
525 when url_image_rgx
526 images_hash[ps].sub!(url_image_rgx,
527 "#{@center_begin}\\\n\\href{#{url}}\n{\\includegraphics*[width=#{width[ps]}pt]{#{dir.path.image_source_include}/#{image}}}#{caption}#{@center_end}")
528 when image_rgx
529 images_hash[ps].sub!(image_rgx,
530 "#{@center_begin}\\\n\\includegraphics*[width=#{width[ps]}pt]{#{dir.path.image_source_include}/#{image}}#{caption}#{@center_end}")
531 end
532 images_hash[ps]
533 elsif @md.opt.f_pth[:pth] =~/\/\S+?\/sisupod\/\S+?\/sisupod\/doc/
534 pt=/(\/\S+?\/sisupod\/\S+?\/sisupod)\/doc/.match(@md.opt.f_pth[:pth])[1]
535 img_src=pt + '/image'
536 if FileTest.file?("#{img_src}/#{image}")
537 case images_hash[ps]
538 when url_image_rgx
539 images_hash[ps].sub!(url_image_rgx,
540 "#{@center_begin}\\\n\\href{#{url}}{\\includegraphics*[width=#{width[ps]}pt]{#{img_src}/#{image}}}#{caption} #{@center_end}")
541 when image_rgx
542 images_hash[ps].sub!(image_rgx,
543 "#{@center_begin}\\\n\\includegraphics*[width=#{width[ps]}pt]{#{img_src}/#{image}}#{caption} #{@center_end}")
544 end
545 images_hash[ps]
546 end
547
548 elsif @md.fns =~/\.(?:ssm\.)?sst$/ \
549 and FileTest.file?("#{dir.path.image_source_include_local}/#{image}")
550 case images_hash[ps]
551 when url_image_rgx
552 images_hash[ps].sub!(url_image_rgx,
553 "#{@center_begin}\\\n\\href{#{url}}{\\includegraphics*[width=#{width[ps]}pt]{#{dir.path.image_source_include_local}/#{image}}}#{caption} #{@center_end}")
554 when image_rgx
555 images_hash[ps].sub!(image_rgx,
556 "#{@center_begin}\\\n\\includegraphics*[width=#{width[ps]}pt]{#{dir.path.image_source_include_local}/#{image}}#{caption} #{@center_end}")
557 end
558 images_hash[ps]
559 elsif @md.fns =~/\.-ss[tm]$/ \
560 and FileTest.file?("#{dir.path.image_source_include_remote}/#{image}")
561 case images_hash[ps]
562 when url_image_rgx
563 images_hash[ps].sub!(url_image_rgx,
564 "#{@center_begin}\\\n\\href{#{url}}{\\includegraphics*[width=#{width[ps]}pt]{#{dir.path.image_source_include_remote}/#{image}}}#{caption}#{@center_end}")
565 when image_rgx
566 images_hash[ps].sub!(image_rgx,
567 "#{@center_begin}\\\n\\includegraphics*[width=#{width[ps]}pt]{#{dir.path.image_source_include_remote}/#{image}}#{caption}#{@center_end}")
568 end
569 images_hash[ps]
570 else
571 SiSU_Screen::Ansi.new(
572 @md.opt.act[:color_state][:set],
573 "ERROR - image:",
574 %{"#{image}" missing},
575 "search locations: #{dir.path.image_source_include_local}, #{dir.path.image_source_include_remote} and #{dir.path.image_source_include}"
576 ).error2 unless @md.opt.act[:quiet][:set]==:on
577 if images_hash[ps] =~url_image_rgx \
578 or images_hash[ps] =~image_rgx
579 images_hash[ps]=''
580 end
581 images_hash[ps]
582 end
583 else
584 link=z.strip #[/(.+?)\\/m,1]
585 images_hash[ps]="\\href{#{url}}{#{link}}#{punctuate}" if images_hash[ps] =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/
586 images_hash[ps]
587 end
588 else images_hash[ps]
589 end
590 images_hash[ps] #=ocn_display(dob) + images_hash[ps]
591 end #while loop
592 images_hash
593 end
594 use_images_hash={}
595 images_hash.each do |k,t|
596 use_images_hash[k]={ l: t, p: t}
597 end
598 dob.tmp=use_images_hash
599 dob
600 end
601 def title
602 title=SiSU_TeX_Pdf::SpecialCharacters.new(@md,@md.title.full).special_characters_safe
603 "\n\\title{#{title}}"
604 end
605 def title_landscape
606 title
607 end
608 def title_portrait
609 title
610 end
611 end
612 class FormatHead
613 require_relative 'prog_text_translation' # prog_text_translation.rb
614 def initialize(md,t_o)
615 @md,@t_o=md,t_o
616 @env=SiSU_Env::InfoEnv.new(@md.fns)
617 if t_o.is_a?(Hash)
618 @txt =t_o[:txt] || nil
619 @subtitle=t_o[:subtitle] || nil
620 @ps=t_o[:paper_size] || nil
621 @ocn=t_o[:ocn] || nil
622 @layout=t_o[:orientation] || nil
623 else
624 p t_o.class
625 p caller
626 end
627 @tx=SiSU_Env::GetInit.new.tex
628 @tex2pdf=@@tex3pdf ||=SiSU_Env::SystemCall.new.tex2pdf_engine
629 @ps=@txt if @txt=~/(?:a4|letter|legal|book|a5|b5)/i
630 @lang ||=SiSU_i18n::Languages.new #.list[@md.opt.lng][:xlp]
631 @author=if defined? @md.creator.author \
632 and @md.creator.author=~/\S+/
633 SiSU_TeX_Pdf::SpecialCharacters.new(@md,@md.creator.author).special_characters_safe
634 else ''
635 end
636 @subject=if defined? @md.classify.subject \
637 and @md.classify.subject=~/\S+/
638 SiSU_TeX_Pdf::SpecialCharacters.new(@md,@md.classify.subject).special_characters_safe
639 else ''
640 end
641 @keywords=if defined? @md.classify.keywords \
642 and @md.classify.keywords=~/\S+/
643 SiSU_TeX_Pdf::SpecialCharacters.new(@md,@md.classify.keywords).special_characters_safe
644 else ''
645 end
646 end
647 def tex_head_lang #babel 18n
648 lang_char_arr=@md.i18n
649 mainlang_char=if @md.i18n == Array \
650 and @md.i18n.length > 0
651 lang_char_arr.slice(0)
652 else @md.opt.lng
653 end
654 mainlang=@lang.list[mainlang_char][:xlp]
655 otherlang=if mainlang != 'english'
656 [ @lang.list['en'][:xlp] ]
657 else []
658 end
659 if lang_char_arr.length > 0
660 lang_char_arr.slice(1..9).each { |ch| otherlang << @lang.list[ch][:xlp] }
661 otherlang=otherlang.uniq
662 end
663 otherlang=otherlang.join(',')
664 { mainlang: mainlang, otherlang: otherlang }
665 end
666 def tex_head_encode
667 texpdf_fontface=if defined? @md.make.texpdf_fontface.main \
668 and not @md.make.texpdf_fontface.main.nil? \
669 and @md.make.texpdf_fontface.main=~/\S{3,}/
670 @md.make.texpdf_fontface.main
671 else @env.font.texpdf.main
672 end
673 texpdf_fontface_sans=if defined? @md.make.texpdf_fontface.sans \
674 and not @md.make.texpdf_fontface.sans.nil? \
675 and @md.make.texpdf_fontface.sans=~/\S{3,}/ # not used
676 @md.make.texpdf_fontface.sans
677 else @env.font.texpdf.sans
678 end
679 texpdf_fontface_serif=if defined? @md.make.texpdf_fontface.serif \
680 and not @md.make.texpdf_fontface.serif.nil? \
681 and @md.make.texpdf_fontface.serif=~/\S{3,}/ # not used
682 @md.make.texpdf_fontface.serif
683 else @env.font.texpdf.serif
684 end
685 texpdf_fontface_mono=if defined? @md.make.texpdf_fontface.mono \
686 and not @md.make.texpdf_fontface.mono.nil? \
687 and @md.make.texpdf_fontface.mono=~/\S{3,}/
688 @md.make.texpdf_fontface.mono
689 else @env.font.texpdf.mono
690 end
691 texpdf_fontface_cjk=if @md.opt.lng =~/zh/ \
692 and defined? @md.make.texpdf_fontface.cjk_zh \
693 and not @md.make.texpdf_fontface.cjk_zh.nil? \
694 and @md.make.texpdf_fontface.cjk_zh=~/\S{3,}/
695 @md.make.texpdf_fontface.cjk_zh
696 elsif @md.opt.lng =~/ja/ \
697 and defined? @md.make.texpdf_fontface.cjk_ja \
698 and not @md.make.texpdf_fontface.cjk_ja.nil? \
699 and @md.make.texpdf_fontface.cjk_ja=~/\S{3,}/
700 @md.make.texpdf_fontface.cjk_ja
701 elsif @md.opt.lng =~/ko/ \
702 and defined? @md.make.texpdf_fontface.cjk_ko \
703 and not @md.make.texpdf_fontface.cjk_ko.nil? \
704 and @md.make.texpdf_fontface.cjk_ko=~/\S{3,}/
705 @md.make.texpdf_fontface.cjk_ko
706 elsif @md.opt.lng =~/(?:zh|ja|ko)/ \
707 and defined? @md.make.texpdf_fontface.cjk \
708 and not @md.make.texpdf_fontface.cjk.nil? \
709 and @md.make.texpdf_fontface.cjk=~/\S{3,}/
710 @md.make.texpdf_fontface.cjk
711 else
712 case @md.opt.lng
713 when /zh/ then @env.font.texpdf.cjk_zh
714 when /ja/ then @env.font.texpdf.cjk_ja
715 when /ko/ then @env.font.texpdf.cjk_ko
716 else @env.font.texpdf.cjk
717 end
718 end
719 # you may wish to check selected font against available fonts:
720 # fc-list :outline -f "%{family}\n"
721 # fc-list :lang=ja
722 case @tex2pdf
723 when /xe/
724 if @md.opt.lng =~/(?:zh|ja|ko)/
725 <<-WOK
726 \\usepackage{ucs, fontspec, xltxtra, xunicode, xeCJK}
727 \\setmainCJKlanguage{#{tex_head_lang[:mainlang]}}
728 \\setCJKmainfont{#{texpdf_fontface_cjk}}
729 \\XeTeXlinebreaklocale "#{tex_head_lang[:mainlang]}"
730 \\XeTeXlinebreakskip = 0pt plus 1pt
731 \\setotherlanguage{#{tex_head_lang[:otherlang]}}
732 \\setmainfont{#{texpdf_fontface}}
733 \\setmonofont[Scale=0.85]{#{texpdf_fontface_mono}}
734 WOK
735 else
736 <<-WOK
737 \\usepackage{polyglossia, ucs, fontspec, xltxtra, xunicode}
738 \\setmainlanguage{#{tex_head_lang[:mainlang]}}
739 \\setotherlanguage{#{tex_head_lang[:otherlang]}}
740 \\setmainfont{#{texpdf_fontface}}
741 \\setmonofont[Scale=0.85]{#{texpdf_fontface_mono}}
742 % \\setsansfont{#{texpdf_fontface_sans}}
743 % \\setromanfont{#{texpdf_fontface_serif}}
744 WOK
745 end
746 when /pdf/
747 if @md.file_encoding =~ /iso-?8859/i #% iso8859
748 <<-WOK
749 % \\usepackage[latin1]{inputenc}
750 \\usepackage{fontspec}
751 WOK
752 else #% utf-8 assumed
753 <<-WOK
754 \\usepackage{babel}
755 \\usepackage{ucs}
756 \\usepackage[utf8x]{inputenc}
757 WOK
758 end
759 end
760 end
761 def tex_head_info
762 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
763 lastdone="Last Generated on: #{Time.now}"
764 rubyv="Ruby version: #{@md.ruby_version}"
765 <<-WOK
766 %% SiSU (Linux & Ruby - \"better ways\") LaTeX output
767 %% #{generator}
768 %% #{rubyv}
769 %% LaTeX output
770 %% #{lastdone}
771 %% SiSU http://www.jus.uio.no/sisu
772 WOK
773 end
774 def tex_head_paper_portrait(d)
775 multicol=(@md.book_idx ? '\usepackage{multicol}' : '')
776 <<-WOK
777 #{tex_head_info}
778 \\documentclass[#{d[:fontsize]},#{d[:papertype]},titlepage]{scrartcl} %with titlepage
779 \\setlength{\\textheight}{#{d[:textheight]}mm} \\setlength{\\textwidth}{#{d[:textwidth]}mm}
780 \\setlength{\\oddsidemargin}{#{d[:oddsidemargin]}} \\setlength{\\evensidemargin}{#{d[:evensidemargin]}}
781 \\setlength{\\topmargin}{#{d[:topmargin]}} \\setlength{\\headheight}{#{d[:headheight]}}
782 \\setlength{\\headsep}{#{d[:headsep]}}
783 \\setlength{\\marginparsep}{#{d[:marginparsep]}}
784 \\setlength{\\marginparwidth}{#{d[:marginparwidth]}}
785 #{multicol}
786 WOK
787 end
788 def tex_head_paper_landscape(d)
789 <<-WOK
790 #{tex_head_info}
791 \\documentclass[#{d[:fontsize]},#{d[:papertype]},landscape,titlepage,twocolumn]{scrartcl} %with titlepage
792 \\setlength{\\textheight}{#{d[:textheight]}mm} \\setlength{\\textwidth}{#{d[:textwidth]}mm}
793 \\setlength{\\oddsidemargin}{#{d[:oddsidemargin]}} \\setlength{\\evensidemargin}{#{d[:evensidemargin]}}
794 \\setlength{\\topmargin}{#{d[:topmargin]}} \\setlength{\\headheight}{#{d[:headheight]}}
795 \\setlength{\\headsep}{#{d[:headsep]}}
796 \\setlength{\\columnsep}{#{d[:columnsep]}}
797 \\setlength{\\marginparsep}{#{d[:marginparsep]}}
798 \\setlength{\\marginparwidth}{#{d[:marginparwidth]}}
799 WOK
800 end
801 def tex_head_paper_portrait_dvi(d)
802 <<-WOK
803 #{tex_head_info}
804 \\documentclass[#{d[:fontsize]},#{d[:papertype]},titlepage]{scrartcl} %with titlepage
805 \\setlength{\\textheight}{#{d[:textheight]}mm} \\setlength{\\textwidth}{#{d[:textwidth]}mm}
806 \\setlength{\\oddsidemargin}{#{d[:oddsidemargin]}} \\setlength{\\evensidemargin}{#{d[:evensidemargin]}}
807 \\setlength{\\topmargin}{#{d[:topmargin]}} \\setlength{\\headheight}{#{d[:headheight]}}
808 \\setlength{\\headsep}{#{d[:headsep]}}
809 \\setlength{\\marginparsep}{#{d[:marginparsep]}}
810 \\setlength{\\marginparwidth}{#{d[:marginparwidth]}}
811 WOK
812 end
813 def tex_head_paper_dimensions
814 d={}
815 fontsize_set=if defined? @env.font.texpdf.size(@md.opt.act[:pdf_font_size]) \
816 and not @env.font.texpdf.size(@md.opt.act[:pdf_font_size]).nil?
817 @env.font.texpdf.size(@md.opt.act[:pdf_font_size])
818 else :na
819 end
820 case @layout
821 when :portrait
822 fontsize=(fontsize_set==:na) ? '11pt' : (fontsize_set + 'pt')
823 d[:papertype],d[:fontsize]='a4paper',fontsize
824 d[:oddsidemargin],d[:evensidemargin],d[:topmargin]='0mm','0mm','-12pt'
825 d[:headheight],d[:headsep],d[:columnsep]='12pt','35pt',''
826 d[:marginparsep],d[:marginparwidth]='4mm','8mm'
827 case @ps #@md.papersize
828 when /a4/i #European default, SiSU default
829 fontsize=(fontsize_set==:na) ? '12pt' : (fontsize_set + 'pt')
830 d[:papertype],d[:fontsize]='a4paper',fontsize
831 d[:textheight],d[:textwidth]=@tx.a4.portrait.h,@tx.a4.portrait.w
832 when /letter/i #U.S. default
833 fontsize=(fontsize_set==:na) ? '12pt' : (fontsize_set + 'pt')
834 d[:papertype],d[:fontsize]='letterpaper',fontsize
835 d[:textheight],d[:textwidth]=@tx.letter.portrait.h,@tx.letter.portrait.w
836 when /legal/i #U.S. alternative
837 fontsize=(fontsize_set==:na) ? '12pt' : (fontsize_set + 'pt')
838 d[:papertype],d[:fontsize]='legalpaper',fontsize
839 d[:textheight],d[:textwidth]=@tx.legal.portrait.h,@tx.legal.portrait.w
840 when /book|b5/i #book default - larger
841 fontsize=(fontsize_set==:na) ? '11pt' : (fontsize_set + 'pt')
842 d[:papertype],d[:fontsize]='b5paper',fontsize
843 d[:oddsidemargin],d[:evensidemargin],d[:topmargin]='-4mm','-4mm','-36pt'
844 d[:headheight],d[:headsep],d[:columnsep]='12pt','20pt',''
845 d[:textheight],d[:textwidth]=@tx.b5.portrait.h,@tx.b5.portrait.w
846 when /a5/i
847 fontsize=(fontsize_set==:na) ? '11pt' : (fontsize_set + 'pt')
848 d[:papertype],d[:fontsize]='a5paper',fontsize
849 d[:oddsidemargin],d[:evensidemargin],d[:topmargin]='-4mm','-4mm','-36pt'
850 d[:headheight],d[:headsep],d[:columnsep]='11pt','12pt',''
851 d[:marginparsep],d[:marginparwidth]='4mm','6mm'
852 d[:textheight],d[:textwidth]=@tx.a5.portrait.h,@tx.a5.portrait.w
853 else #default currently A4
854 fontsize=(fontsize_set==:na) ? '12pt' : (fontsize_set + 'pt')
855 d[:papertype],d[:fontsize]='a4paper',fontsize
856 d[:textheight],d[:textwidth]=@tx.a4.portrait.h,@tx.a4.portrait.w
857 end
858 when :landscape
859 fontsize=(fontsize_set==:na) ? '11pt' : (fontsize_set + 'pt')
860 d[:papertype],d[:fontsize]='a4paper',fontsize
861 d[:oddsidemargin],d[:evensidemargin],d[:topmargin]='6mm','6mm','-12mm'
862 d[:headheight],d[:headsep],d[:columnsep]='12pt','20pt','40pt'
863 d[:marginparsep],d[:marginparwidth]='4mm','8mm'
864 case @ps #@md.papersize
865 when /a4/i #European default, SiSU default
866 fontsize=(fontsize_set==:na) ? '11pt' : (fontsize_set + 'pt')
867 d[:papertype],d[:fontsize]='a4paper',fontsize
868 d[:textheight],d[:textwidth]=@tx.a4.landscape.h,@tx.a4.landscape.w
869 when /letter/i #U.S. default
870 fontsize=(fontsize_set==:na) ? '11pt' : (fontsize_set + 'pt')
871 d[:papertype],d[:fontsize]='letterpaper',fontsize
872 d[:textheight],d[:textwidth]=@tx.letter.landscape.h,@tx.letter.landscape.w
873 when /legal/i #U.S. alternative
874 fontsize=(fontsize_set==:na) ? '11pt' : (fontsize_set + 'pt')
875 d[:papertype],d[:fontsize],d[:columnsep]='legalpaper',fontsize,'48pt'
876 d[:textheight],d[:textwidth]=@tx.legal.landscape.h,@tx.legal.landscape.w
877 when /book|b5/i #book default - larger
878 fontsize=(fontsize_set==:na) ? '11pt' : (fontsize_set + 'pt')
879 d[:papertype],d[:fontsize],d[:columnsep]='b5paper',fontsize,'35pt'
880 d[:textheight],d[:textwidth]=@tx.b5.landscape.h,@tx.b5.landscape.w
881 when /a5/i
882 fontsize=(fontsize_set==:na) ? '10pt' : (fontsize_set + 'pt')
883 d[:papertype],d[:fontsize],d[:columnsep]='a5paper',fontsize,'32pt'
884 d[:textheight],d[:textwidth]=@tx.a5.landscape.h,@tx.a5.landscape.w
885 else #default currently A4
886 fontsize=(fontsize_set==:na) ? '12pt' : (fontsize_set + 'pt')
887 d[:papertype],d[:fontsize]='a4paper',fontsize
888 d[:textheight],d[:textwidth]=@tx.a4.landscape.h,@tx.a4.landscape.w
889 end
890 end
891 d
892 end
893 def tex_head_paper
894 case @layout
895 when :portrait
896 tex_head_paper_portrait(tex_head_paper_dimensions)
897 when :landscape
898 tex_head_paper_landscape(tex_head_paper_dimensions)
899 end
900 end
901 def hyperlinks_monochrome
902 <<-WOK
903 colorlinks=true,
904 urlcolor=myblack,
905 filecolor=myblack,
906 linkcolor=myblack,
907 WOK
908 end
909 def hyperlinks_colored
910 <<-WOK
911 colorlinks=true,
912 urlcolor=myblue, % \\href{...}{...} external url
913 filecolor=mygreen, % \\href{...} local file
914 linkcolor=myred, % \\href{...} and \\pageref{...}
915 WOK
916 end
917 def hyperlinks_color?
918 case @layout
919 when :portrait then hyperlinks_monochrome
920 if @env.texpdf_hyperlinks(@md.opt.act[:pdf_hyperlink_colors]).portrait != :na
921 case @env.texpdf_hyperlinks(@md.opt.act[:pdf_hyperlink_colors]).portrait
922 when :color then hyperlinks_colored
923 when :mono then hyperlinks_monochrome
924 else p __LINE__.to_s + ':error'
925 end
926 else hyperlinks_monochrome
927 end
928 when :landscape
929 if @env.texpdf_hyperlinks(@md.opt.act[:pdf_hyperlink_colors]).landscape != :na
930 case @env.texpdf_hyperlinks(@md.opt.act[:pdf_hyperlink_colors]).landscape
931 when :color then hyperlinks_colored
932 when :mono then hyperlinks_monochrome
933 else p __LINE__.to_s + ':error'
934 end
935 else hyperlinks_colored
936 end
937 end
938 end
939 def tex_head_pdftex
940 author=if defined? @md.creator.author \
941 and @md.creator.author=~/\S+/
942 SiSU_TeX_Pdf::SpecialCharacters.new(@md,@md.creator.author).special_characters_safe_no_urls
943 else ''
944 end
945 <<-WOK
946 \\usepackage{alltt}
947 \\usepackage{thumbpdf}
948 \\usepackage[#{@tex2pdf},
949 #{hyperlinks_color?.strip}
950 pdftitle={#{@txt}},
951 pdfauthor={#{author}},
952 pdfsubject={#{@subject}},
953 pdfkeywords={#{@keywords}},
954 pageanchor=true,
955 plainpages=true,
956 pdfpagelabels=true,
957 pagebackref,
958 bookmarks=true,
959 bookmarksopen=true,
960 pdfmenubar=true,
961 pdfpagemode=UseOutline,
962 pdffitwindow=true,
963 pdfwindowui=true,
964 plainpages=false,
965 % pdfusetitle=true,
966 % pdfpagelayout=SinglePage,
967 % pdfpagelayout=TwoColumnRight,
968 % pdfpagelayout=TwoColumnLeft,
969 % pdfstartpage=3,
970 pdfstartview=FitH
971 ]
972 {hyperref}
973 %% trace lost characters
974 % \\tracinglostchars = 1
975 % \\tracingonline = 1
976 \\usepackage[usenames]{color}
977 \\definecolor{myblack}{rgb}{0,0,0}
978 \\definecolor{myred}{rgb}{0.75,0,0}
979 \\definecolor{mygreen}{rgb}{0,0.5,0}
980 \\definecolor{myblue}{rgb}{0,0,0.5}
981 \\definecolor{mywhite}{rgb}{1,1,1}
982 \\usepackage{url}
983 \\urlstyle{sf}
984 %\\usepackage{breakurl}
985 WOK
986 end
987 def tex_head_codeblock(codeblock_box_type)
988 codeblock_box=if codeblock_box_type=='listings'
989 <<-WOK
990 \\usepackage{listings}
991 \\usepackage{color}
992 \\usepackage{textcomp}
993 WOK
994 elsif codeblock_box_type=='boites'
995 "\\usepackage{boites}"
996 else
997 "\\usepackage{boites}"
998 end
999 codeblock_box
1000 end
1001 def tex_head_misc
1002 <<-WOK
1003 \\usepackage{textcomp}
1004 \\usepackage[parfill]{parskip}
1005 \\usepackage[normalem]{ulem}
1006 \\usepackage{soul}
1007 \\usepackage{longtable}
1008 \\usepackage[tc]{titlepic}
1009 \\usepackage{graphicx}
1010 \\makeatletter
1011 \\parindent0pt
1012 %\\usepackage{mathptmx}
1013 \\usepackage{amssymb}
1014 % amssymb used for backslash
1015 WOK
1016 end
1017 def document_head_with_orientation(codeblock_box_type)
1018 endnotes=("\\usepackage{endnotes}" if @txt =~/endnotes?/) || '' #not implemented see also def endnotes
1019 @lang.list[@md.i18n[0]][:xlp]
1020 <<-WOK
1021 #{tex_head_paper}
1022 #{tex_head_encode}
1023 #{tex_head_pdftex}
1024 #{tex_head_misc}
1025 #{tex_head_codeblock(codeblock_box_type)}
1026 \\setcounter{secnumdepth}{2}
1027 \\setcounter{tocdepth}{4}
1028 \\makeatletter
1029 #{endnotes}
1030 \\usepackage[multiple,ragged]{footmisc}
1031 \\setlength\\footnotemargin{12pt}
1032 \\usepackage[para]{manyfoot}
1033 \\DeclareNewFootnote{A}
1034 %\\DeclareNewFootnote[para]{A}
1035 \\newenvironment{ParagraphIndent}[1]%
1036 {
1037 \\begin{list}{}{%
1038 \\setlength\\topsep{0pt}%
1039 \\addtolength{\\leftmargin}{#1}
1040 \\setlength\\parsep{0pt plus 1pt}%
1041 }
1042 \\item[]
1043 }
1044 {\\end{list}}
1045
1046 \\newenvironment{ParagraphHang}[2]%
1047 {
1048 \\begin{list}{}{%
1049 \\setlength\\topsep{0pt}%
1050 \\addtolength{\\leftmargin}{#1}
1051 \\itemindent=#2
1052 \\setlength\\parsep{0pt plus 1pt}%
1053 }
1054 \\item[]
1055 }
1056 {\\end{list}}
1057
1058 \\newenvironment{Bullet}[1]%
1059 {
1060 \\begin{list}{}{%
1061 \\setlength\\topsep{0pt}%
1062 \\addtolength{\\leftmargin}{#1}
1063 \\itemindent=-1em
1064 \\setlength\\parsep{0pt plus 1pt}%
1065 }
1066 \\item[]
1067 }
1068 {\\end{list}}
1069 \\usepackage{fancyhdr}
1070 \\lhead{}
1071 \\renewcommand{\\part}{\\\@startsection
1072 {part}{1}{-2mm}%
1073 {-\\baselineskip}{0.5\\baselineskip}%
1074 {\\bfseries\\large\\upshape\\raggedright}}
1075 \\renewcommand{\\section}{\\\@startsection
1076 {section}{2}{-2mm}%
1077 {-\\baselineskip}{0.5\\baselineskip}%
1078 {\\bfseries\\large\\upshape\\raggedright}}
1079 \\renewcommand{\\subsection}{\\\@startsection
1080 {subsection}{3}{-2mm}%
1081 {-\\baselineskip}{0.5\\baselineskip}%
1082 {\\bfseries\\large\\upshape\\raggedright}}
1083 \\renewcommand{\\subsubsection}{\\\@startsection
1084 {subsubsection}{4}{-2mm}%
1085 {-\\baselineskip}{0.5\\baselineskip}%
1086 {\\normalfont\\normalsize\\bfseries\\raggedright}}
1087 \\renewcommand{\\paragraph}{\\\@startsection
1088 {paragraph}{5}{-2mm}%
1089 {-\\baselineskip}{0.5\\baselineskip}%
1090 {\\normalfont\\normalsize\\itshape\\raggedright}}
1091 \\renewcommand{\\subparagraph}{\\\@startsection
1092 {subparagraph}%{6}%{-2mm}%
1093 {-\\baselineskip}{0.5\\baselineskip}%
1094 {\\normalfont\\normalsize\\itshape\\raggedright}}
1095 % \\makeatother
1096 \\selectlanguage{#{@lang.list[@md.i18n[0]][:xlp]}}
1097 WOK
1098 end
1099 def a4generic
1100 end
1101 end
1102 class SpecialCharacters
1103 include SiSU_Parts_TeXpdf
1104 def initialize(md,str,is=:default)
1105 @md,@txt,@is=md,str,is
1106 @tex2pdf=@@tex3pdf ||=SiSU_Env::SystemCall.new.tex2pdf_engine
1107 end
1108 def xetex_code_listings(str,is=:default) # ~ ^ $ & % _ { } #LaTeX special characters - KEEP list
1109 word=str.scan(/\S+|\n/) #unless line =~/^(?:@\S|%+\s)/
1110 para_array=[]
1111 str=if word
1112 word.each do |w| # _ - / # | : ! ^ ~
1113 w=w.gsub(/#{Mx[:gl_o]}#lt#{Mx[:gl_c]}/,'<').gsub(/#{Mx[:gl_o]}#gt#{Mx[:gl_c]}/,'>').
1114 gsub(/[\\]?~/,'~').
1115 gsub(/[#{Mx[:br_line]}#{Mx[:br_paragraph]}]/,"\n"). #watch
1116 gsub(/#{Mx[:gl_o]}#(?:126|152)#{Mx[:gl_c]}/,'~'). #126 usual
1117 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
1118 para_array << w
1119 end
1120 str=para_array.join(' ')
1121 str=str.strip unless is==:code
1122 str
1123 else ''
1124 end
1125 str=str.gsub(/\s*#{Mx[:mk_o]}:name#\S+?#{Mx[:mk_c]}\s*/,' ').
1126 gsub(/.+?<-#>/,'').
1127 gsub(/#{Mx[:br_eof]}/,'').
1128 gsub(/#{Mx[:br_endnotes]}/,'').
1129 #problem sequence ->
1130 gsub(/&(?:lt|#060);/,'<'). # < SiSU special character also LaTeX
1131 gsub(/#{Mx[:gl_o]}#(?:gt|062)#{Mx[:gl_c]}/,'>'). # > SiSU special character also LaTeX
1132 gsub(/#{Mx[:gl_o]}#123#{Mx[:gl_c]}/,'{'). # { SiSU special character also LaTeX
1133 gsub(/#{Mx[:gl_o]}#125#{Mx[:gl_c]}/,'}'). # } SiSU special character also LaTeX
1134 gsub(/#{Mx[:gl_o]}#(?:126|152)#{Mx[:gl_c]}/,'~'). # ~ SiSU special character also LaTeX
1135 gsub(/#{Mx[:gl_o]}#035#{Mx[:gl_c]}/,'#'). # SiSU special character also LaTeX
1136 gsub(/#{Mx[:gl_o]}#033#{Mx[:gl_c]}/,'!'). # ! SiSU not really special sisu character but done, also LaTeX
1137 #gsub(/(^|\s)\*\s/,'\1\asterisk '). # * should you wish to escape astrisk e.g. describing \*{bold}*
1138 gsub(/#{Mx[:gl_o]}#042#{Mx[:gl_c]}/,'*'). # * should you wish to escape astrisk e.g. describing \*{bold}*
1139 gsub(/#{Mx[:gl_o]}#045#{Mx[:gl_c]}/,'-'). # - SiSU special character also LaTeX
1140 gsub(/#{Mx[:gl_o]}#043#{Mx[:gl_c]}/,'+'). # + SiSU special character also LaTeX
1141 gsub(/#{Mx[:gl_o]}#044#{Mx[:gl_c]}/,','). # + SiSU special character also LaTeX
1142 gsub(/#{Mx[:gl_o]}#038#{Mx[:gl_c]}/,'&'). #unless @txt=~/<:code>/ # / SiSU special character also LaTeX
1143 gsub(/#{Mx[:gl_o]}#047#{Mx[:gl_c]}/,'/'). # / SiSU special character also LaTeX
1144 gsub(/#{Mx[:gl_o]}#092#{Mx[:gl_c]}/,'\\'). # \ SiSU special character also LaTeX
1145 gsub(/#{Mx[:gl_o]}#095#{Mx[:gl_c]}/,'_'). # _ SiSU special character also LaTeX
1146 gsub(/#{Mx[:gl_o]}#124#{Mx[:gl_c]}/,'|'). # | SiSU not really special sisu character but done, also LaTeX
1147 gsub(/#{Mx[:gl_o]}#058#{Mx[:gl_c]}/,':'). # : SiSU not really special sisu character but done, also LaTeX
1148 gsub(/#{Mx[:gl_o]}#094#{Mx[:gl_c]}|\^/,'^'). # ^ SiSU not really special sisu character but done, also LaTeX
1149 ##watch placement, problem sequence ^
1150 gsub(/<sup><font face=symbol>&atild;<\/font><\/sup>/,' ').
1151 gsub(/\\copy(right|mark)?/,'<=copymark>') # ok problem with superscript
1152 end
1153 def xetex_special_characters_1(str,is=:default) # ~ ^ $ & % _ { } #LaTeX special characters - KEEP list
1154 word=str.scan(/\S+|\n/) #unless line =~/^(?:@\S|%+\s)/
1155 para_array=[]
1156 str=if word
1157 word.each do |w| # _ - / # | : ! ^ ~
1158 if w !~/https?:/ \
1159 and w=~/\/\S+?\// \
1160 and w.length > 6
1161 w=w.gsub(/([_.\/])/,'\1\-')
1162 end
1163 w=w.gsub(/#{Mx[:gl_o]}#lt#{Mx[:gl_c]}/,'<').gsub(/#{Mx[:gl_o]}#gt#{Mx[:gl_c]}/,'>').
1164 gsub(/[\\]?~/,'<=tilde>').
1165 gsub(/[#{Mx[:br_line]}#{Mx[:br_paragraph]}]/,' \newline '). #watch
1166 gsub(/#{Mx[:gl_o]}#(?:126|152)#{Mx[:gl_c]}/,'<=tilde>'). #126 usual
1167 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
1168 if w !~/#{Mx[:rel_o]}/ \
1169 and w !~/#{Mx[:gl_o]}#/
1170 w=w.gsub(/\#/,'<=hash>')
1171 end
1172 para_array << w
1173 end
1174 str=para_array.join(' ')
1175 str=str.strip unless is==:code
1176 str
1177 else ''
1178 end
1179 str=str.gsub(/\s*#{Mx[:mk_o]}:name#\S+?#{Mx[:mk_c]}\s*/,' ').
1180 gsub(/.+?<-#>/,'').
1181 gsub(/#{Mx[:br_eof]}/,'').
1182 gsub(/#{Mx[:br_endnotes]}/,'')
1183 #problem sequence ->
1184 str=str.gsub(/&(?:nbsp);|#{Mx[:nbsp]}/,'\hardspace') unless is==:code # < SiSU special character also LaTeX
1185 str=str.gsub(/&(?:lt|#060);/,'\lt'). # < SiSU special character also LaTeX
1186 gsub(/#{Mx[:gl_o]}#(?:gt|062)#{Mx[:gl_c]}/,'\gt'). # > SiSU special character also LaTeX
1187 gsub(/#{Mx[:gl_o]}#123#{Mx[:gl_c]}/,'\curlyopen'). # { SiSU special character also LaTeX
1188 gsub(/#{Mx[:gl_o]}#125#{Mx[:gl_c]}/,'\curlyclose'). # } SiSU special character also LaTeX
1189 gsub(/#{Mx[:gl_o]}#(?:126|152)#{Mx[:gl_c]}/,'<=tilde>'). # ~ SiSU special character also LaTeX
1190 gsub(/#{Mx[:gl_o]}#035#{Mx[:gl_c]}/,'\#'). # # SiSU special character also LaTeX
1191 gsub(/#{Mx[:gl_o]}#033#{Mx[:gl_c]}/,'!'). # ! SiSU not really special sisu character but done, also LaTeX
1192 gsub(/(^|\s)\*\s/,'\1\asterisk '). # * should you wish to escape astrisk e.g. describing \*{bold}*
1193 gsub(/#{Mx[:gl_o]}#042#{Mx[:gl_c]}/,'\*'). # * should you wish to escape astrisk e.g. describing \*{bold}*
1194 gsub(/#{Mx[:gl_o]}#045#{Mx[:gl_c]}/,'-'). # - SiSU special character also LaTeX
1195 gsub(/#{Mx[:gl_o]}#043#{Mx[:gl_c]}/,'+'). # + SiSU special character also LaTeX
1196 gsub(/#{Mx[:gl_o]}#044#{Mx[:gl_c]}/,','). # + SiSU special character also LaTeX
1197 gsub(/#{Mx[:gl_o]}#038#{Mx[:gl_c]}/,'<=amp>'). #unless @txt=~/<:code>/ # / SiSU special character also LaTeX
1198 gsub(/#{Mx[:gl_o]}#047#{Mx[:gl_c]}/,'\slash'). # / SiSU special character also LaTeX
1199 gsub(/#{Mx[:gl_o]}#092#{Mx[:gl_c]}/,'\textbackslash'). # \ SiSU special character also LaTeX
1200 gsub(/#{Mx[:gl_o]}#095#{Mx[:gl_c]}/,'<=underscore>'). # _ SiSU special character also LaTeX
1201 gsub(/#{Mx[:gl_o]}#124#{Mx[:gl_c]}/,'|'). # | SiSU not really special sisu character but done, also LaTeX
1202 gsub(/#{Mx[:gl_o]}#058#{Mx[:gl_c]}/,':'). # : SiSU not really special sisu character but done, also LaTeX
1203 gsub(/#{Mx[:gl_o]}#094#{Mx[:gl_c]}|\^/,'\caret'). # ^ SiSU not really special sisu character but done, also LaTeX
1204 ##watch placement, problem sequence ^
1205 gsub(/<sup><font face=symbol>&atild;<\/font><\/sup>/,' ').
1206 gsub(/\\copy(right|mark)?/,'<=copymark>') # ok problem with superscript
1207 end
1208 def xetex_special_characters_2(str,is=:default)
1209 str=str.gsub(/#{Mx[:gl_o]}#156#{Mx[:gl_c]}/,'\oe ').
1210 gsub(/\$/,'\$').
1211 gsub(/\#/,'\#').
1212 gsub(/\%/,'\%').
1213 gsub(/\~/,'\~') #revist, should not be necessary to mark remaining tildes
1214 if str !~/^\s*#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}image\s/
1215 str=str.gsub(/_/,'\_')
1216 end
1217 str=str.gsub(/\{/,'\{').
1218 gsub(/\}/,'\}')
1219 str=if is==:code
1220 str.gsub(/&/,'{\\\&}').
1221 gsub(/\\~(\\\{)/,'{$\tilde$}\1').
1222 gsub(/(\\\})\\~/,'\1{$\tilde$}').
1223 gsub(/\\~(\[)/,'{$\tilde$}\1').
1224 gsub(/(\])\\~/,'\1{$\tilde$}').
1225 gsub(/<=tilde>/,'{$\tilde$}').
1226 gsub(/<=hash>/,'{\#}')
1227 else
1228 str.gsub(/&nbsp;|#{Mx[:nbsp]}/,'~'). # ~ character for hardspace
1229 gsub(/&/,'<=amp>')
1230 end
1231 str=str.gsub(/&\S+?;/,' ').
1232 gsub(/§/u,'\S'). #latex: space between next character not preserved? #str.gsub(/§ /,'\S ')
1233 gsub(/£/u,'\pounds').
1234 gsub(/<a href=".+?">/,' ').
1235 gsub(/<\/a>/,' ')
1236 unless is==:no_urls
1237 str=str.gsub(/((?:^|\s)#{Mx[:lnk_c]})#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,
1238 '\1\begin{scriptsize}\url{\2}\end{scriptsize}\3'). #special case \{ e.g. \}http://url
1239 gsub(/#{Mx[:url_o]}\\_(\S+?)#{Mx[:url_c]}/,
1240 '\begin{scriptsize}\url{\1}\end{scriptsize}'). #special case \{ e.g. \}http://url
1241 gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,
1242 '\begin{scriptsize}\\url{\1}\end{scriptsize}') #specially escaped url no decoration
1243 end
1244 if is !=:code \
1245 and is !=:no_urls
1246 str=str.gsub(/(^|#{Mx[:gl_c]}|\s)((?:https?|file|ftp):\/\/\S+?\.[^'"\s]+?)([;.,]?(?=\s|$))/,
1247 "\\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
1248 end
1249 str=str.gsub(/<:ee>/,'').
1250 gsub(/<!>/,' '). #proposed change, insert, but may be redundant
1251 gsub(/<(br|p)>|<\/\s*(br|p)>|<(br|p)\s*\/>/," #{Tex[:backslash]*2} "). # Work Area
1252 gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/,'\begin{bfseries}\1 \end{bfseries}').
1253 gsub(/<h\d+>(.+?)<\/h\d+>/,'\begin{bfseries}\1 \end{bfseries}').
1254 gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/,'\emph{\1}').
1255 gsub(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/,'\uline{\1}'). # ulem
1256 gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,"``\\1''"). # quote #CHECK
1257 gsub(/#{Mx[:fa_insert_o]}(.+?)#{Mx[:fa_insert_c]}/,'\uline{\1}'). # ulem
1258 gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/,'\sout{\1}'). # ulem
1259 gsub(/#{Mx[:fa_superscript_o]}(.+?)#{Mx[:fa_superscript_c]}/,"\$^{\\textrm{\\1}}\$").
1260 gsub(/#{Mx[:fa_subscript_o]}(.+?)#{Mx[:fa_subscript_c]}/,"\$_{\\textrm{\\1}}\$").
1261 gsub(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/,'\begin{monosp}\1\end{monosp}')
1262 unless is==:code
1263 str=str.gsub(/"(.+?)"/,'“\1”'). # quote marks / quotations open & close " need condition exclude for code
1264 gsub(/\s+"/,' “'). # open "
1265 gsub(/^(#{Mx[:lv_o]}[1-6-]:\S*?#{Mx[:lv_c]}|<.+?>)?\s*"/,'\1“'). #fix Mx[:lv_o] # open "
1266 gsub(/"(\s|\.|,|:|;)/,'”\1'). # close "
1267 gsub(/"(#{Mx[:lv_o]}[1-6-]:\S*?#{Mx[:lv_c]}|<.+?>)?\s*$/,'”\1'). #fix Mx[:lv_o] # close "
1268 gsub(/"(\.|,)/,'”'). # close "
1269 gsub(/\s+'/,' `'). # open '
1270 gsub(/^(#{Mx[:lv_o]}[1-6-]:\S*?#{Mx[:lv_c]}|<.+?>)?\s*'/,'\1`') #fix Mx[:lv_o] # open '
1271 end
1272 str=str.gsub(/(<font.*?>|<\/font>)/,'').
1273 gsub(/\s*#{Mx[:fa_superscript_o]}(\S+?)#{Mx[:fa_superscript_c]}/,'^\1')
1274 str
1275 end
1276 def xetex_special_characters_3(str)
1277 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
1278 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
1279 while str =~/(https?:\/\/\S+?)(?:<=tilde>\S+)+/ #tilde in urls \href treated differently from text #FIX
1280 str=str.gsub(/(https?:\/\/\S+?)(?:<=tilde>(\S+))+/,'\1~\2')
1281 end
1282 str=str.gsub(/<=tilde>/,'{$\tilde$}').
1283 gsub(/(https?:\/\/\S+?)(?:(?:<=hash>)(\S+))+/,'\1#\2'). #hash in urls \href treated differently from text #FIX
1284 gsub(/<=hash>/,'{\#}')
1285 while str =~/(https?:\/\/\S+?)(?:<=amp>\S+)+/ #amp in urls \href treated differently from text #FIX
1286 str=str.gsub(/(https?:\/\/\S+?)(?:<=amp>(\S+))+/,'\1&\2')
1287 end
1288 str=str.gsub(/<=amp>/,'{\\\&}'). #changed ... 2005
1289 gsub(/<=copymark>\s*(.+)/,
1290 '^\copyright \textnormal{\1} \2') # watch likely to be problematic
1291 str
1292 end
1293 def special_characters_safe_close(str)
1294 str=str.gsub(/<=tilde>/,'{$\tilde$}').
1295 gsub(/<=hash>/,'{\#}').
1296 gsub(/<=amp>/,'{\\\&}'). #changed ... 2005
1297 gsub(/<=copymark>\s*(.+)/,
1298 '^\copyright \textnormal{\1} \2') # watch likely to be problematic
1299 end
1300 def special_characters_code_fix(str)
1301 str=str.gsub(/<=tilde>/,'{$\tilde$}')
1302 str
1303 end
1304 def special_characters_unsafe_1(str) #depreciated, make obsolete
1305 # some substitutions are sequence sensitive, rearrange with care.
1306 str=str.gsub(/\\textbackslash (copyright|clearpage|newpage)/,"\\\\\\1") #kludge bad solution, find out where tail is sent through specChar !
1307 str
1308 end
1309 def special_characters # special characters - some substitutions are sequence sensitive, rearrange with care
1310 str,is=@txt,@is
1311 str=xetex_special_characters_1(str,is) unless str.nil?
1312 str=special_characters_unsafe_1(str) unless str.nil? #xetex_special_characters_unsafe_1(@txt)
1313 str=xetex_special_characters_2(str,is) unless str.nil? #issues with xetex
1314 str=xetex_special_characters_3(str) unless str.nil?
1315 @txt=str
1316 end
1317 def special_word_break_points
1318 str=@txt
1319 str=str.gsub(/([_,.;:\/|=])/,'\1\-').
1320 gsub(/(--)(\S{4,})/,'\1\-\2')
1321 @txt=str
1322 end
1323 def special_number_break_points
1324 str=@txt
1325 str=str.gsub(/([0-9a-f]{8})/i,'\1\-')
1326 @txt=str
1327 end
1328 def special_characters_safe # special characters - some substitutions are sequence sensitive, rearrange with care
1329 str,is=@txt,@is
1330 str=xetex_special_characters_1(str,is) unless str.nil?
1331 str=xetex_special_characters_2(str,is) unless str.nil? # remove this to start with, causes issues
1332 str=special_characters_safe_close(str) unless str.nil?
1333 @txt=str
1334 end
1335 def special_characters_safe_no_urls
1336 str,is=@txt,:no_urls
1337 str=xetex_special_characters_1(str,is) unless str.nil?
1338 str=xetex_special_characters_2(str,is) unless str.nil? # remove this to start with, causes issues
1339 str=special_characters_safe_close(str) unless str.nil?
1340 @txt=str
1341 end
1342 def characters_code_listings # special characters - some substitutions are sequence sensitive, rearrange with care
1343 str,is=@txt,@is
1344 str=xetex_code_listings(str,is) unless str.nil?
1345 @txt=str
1346 end
1347 def special_characters_code
1348 str=@txt
1349 str=str.gsub(/ \\\\([ #{Mx[:br_nl]}]+|$)/,' \textbackslash\textbackslash\hardspace\1')
1350 str
1351 end
1352 end
1353 class UseTeX
1354 include SiSU_Parts_TeXpdf
1355 attr_accessor :url,:txt,:date
1356 def initialize(md)
1357 @md=md
1358 @date=SiSU_Env::InfoDate.new # #{@date.year}
1359 @copymark='{\\begin{footnotesize}\\raisebox{1ex}{\\copyright}\\end{footnotesize}}'
1360 end
1361 def skip
1362 "\n\\vspace*{\\smallskipamount} \n"
1363 end
1364 def paraskip_normal
1365 '\setlength{\parskip}{1ex plus0.5ex minus0.2ex}'
1366 end
1367 def paraskip_small
1368 '\setlength{\parskip}{0.5ex plus0.2ex minus0.1ex}'
1369 end
1370 def paraskip_tiny
1371 '\setlength{\parskip}{0.1ex plus0.1ex minus0.1ex}'
1372 end
1373 def skip_small
1374 "\\smallskip{}"
1375 end
1376 def skip_small_vspace
1377 "\n\\vspace*{\\smallskipamount} \n"
1378 end
1379 def skip_small_footnote
1380 end
1381 def skip_medium
1382 "\n\\medskip{}\n\n"
1383 end
1384 def skip_dummy
1385 "\n"
1386 end
1387 def header
1388 "\\lhead[ ]{ }\n" +
1389 "\\chead[ \\fancyplain{} \\bfseries \\footnotesize \\leftmark ]{ \\fancyplain{} \\bfseries \\footnotesize \\rightmark }\n" +
1390 "\\rhead[ ]{ }\n"
1391 end
1392 def footer
1393 "\\lfoot[\\textrm{\\thepage}]{\\tiny \\href{#{@md.footer_links[:left][:url]}}{#{@md.footer_links[:left][:say]}}}\n" +
1394 "\\cfoot{\\href{#{@md.footer_links[:center][:url]}}{#{@md.footer_links[:center][:say]}}}\n" +
1395 "\\rfoot[\\tiny \\href{}{}]{\\textrm{\\thepage}}\n"
1396 end
1397 def site
1398 if not the_url.home.empty? \
1399 and not the_url.home_txt.empty?
1400 "\n\\date{\\begin{tiny} \\end{tiny}}"
1401 else ''
1402 end
1403 end
1404 def owner_chapter
1405 "Contact Details for Original Promulgating Authority"
1406 end
1407 #BOOK standard dimensions - 229x156
1408 def newpage(orientation)
1409 case orientation
1410 when :landscape # using longtable latex package
1411 <<-WOK
1412 \\clearpage
1413 WOK
1414 when :portrait
1415 <<-WOK
1416 \\newpage
1417 WOK
1418 end
1419 end
1420 def sisu_rights
1421 v=SiSU_Env::InfoVersion.instance.get_version
1422 base_prog_txt=if @md.base_program
1423 case @md.base_program
1424 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"
1425 else ''
1426 end
1427 else ''
1428 end
1429 <<-WOK
1430 \\\\ ~
1431 {\\begin{footnotesize}#{base_prog_txt}
1432 \\\\ 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}
1433 \\\\ Copyright #{@copymark} 1997, current #{@date.year_static} Ralph Amissah, All Rights Reserved.
1434 \\\\ SiSU is software for document structuring, publishing and search (with object citation numbering), \\href{http://www.sisudoc.org}{www.sisudoc.org}
1435 \\\\ 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}.
1436 {\\end{footnotesize}
1437 \\\\
1438 WOK
1439 end
1440 def doc_sc_info_footnote_full
1441 <<-WOK
1442 \\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}}}}
1443 WOK
1444 end
1445 def doc_sc_info_footnote_brief
1446 " \\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}"
1447 end
1448 def doc_sc_info
1449 v=SiSU_Env::InfoVersion.instance.get_version
1450 <<-WOK
1451 \\\\
1452 {\\begin{footnotesize}
1453 Document version information: \\\\
1454 \\emph{sourcefile} \\uline{#{@md.fnstex}}; \\emph{version} \\uline{#{@md.sc_number}}; \\emph{date} \\uline{#{@md.sc_date}}; \\emph{time} \\uline{#{@md.sc_time}} \\\\
1455 Generated by \\href{http://www.jus.uio.no/sisu}{SiSU www.jus.uio.no/sisu }\\- version information: \\\\
1456 \\uline{ #{v.project} #{v.version} of #{v.date_stamp}}
1457 \\end{footnotesize}}&
1458 WOK
1459 end
1460 def doc_no_sc_info
1461 v=SiSU_Env::InfoVersion.instance.get_version
1462 <<-WOK
1463 \\\\
1464 {\\begin{small}
1465 Document information: \\\\
1466 \\emph{sourcefile} \\uline{#{@md.fnstex}} \\\\
1467 Generated by \\href{http://www.jus.uio.no/sisu}{SiSU www.jus.uio.no/sisu } \\\\ version information: \\
1468 \\uline{ #{v.project} #{v.version} of #{v.date_stamp}}
1469
1470 \\end{small}}&
1471 WOK
1472 end
1473 def endnotes #not used should be inserted before MetaData section which preceeds doc_tail, but is "part of document"
1474 <<-WOK
1475 \\subsection*{Endnotes}
1476 \\addcontentsline{toc}{section}{Endnotes}
1477 \\
1478 \\listofendnotes
1479 WOK
1480 end
1481 end
1482 end
1483 __END__
1484 ag usepackage texpdf*
1485 ag usepackage texpdf* | ag '\{.+?\}'
1486 # texpdf_format.rb
1487 ag usepackage texpdf* | ag --only-matching '\{.+?\}'
1488
1489 * sort & make unique
1490 @tex2pdf
1491 alltt.sty
1492 amssymb.sty
1493 babel.sty
1494 boites.sty
1495 breakurl.sty
1496 color.sty
1497 endnotes.sty
1498 fancyhdr.sty
1499 fontspec.sty
1500 footmisc.sty
1501 graphicx.sty
1502 inputenc.sty
1503 listings.sty
1504 longtable.sty
1505 manyfoot.sty
1506 mathptmx.sty
1507 multicol.sty
1508 parskip.sty
1509 polyglossia.sty
1510 soul.sty
1511 textcomp.sty
1512 thumbpdf.sty
1513 titlepic.sty
1514 ucs.sty
1515 ulem.sty
1516 url.sty
1517 xeCJK.sty
1518 xltxtra.sty
1519 xunicode.sty
1520
1521 * debian related
1522 ** found in
1523
1524 alltt.sty
1525 texlive-latex-base: /usr/share/texlive/texmf-dist/tex/latex/base/alltt.sty
1526 amssymb.sty
1527 texlive-base: /usr/share/texlive/texmf-dist/tex/latex/amsfonts/amssymb.sty
1528 babel.sty
1529 texlive-latex-base: /usr/share/texlive/texmf-dist/tex/generic/babel/babel.sty
1530 boites.sty
1531 texlive-latex-extra: /usr/share/texlive/texmf-dist/tex/latex/boites/boites.sty
1532 breakurl.sty
1533 texlive-latex-extra: /usr/share/texlive/texmf-dist/tex/latex/breakurl/breakurl.sty
1534 color.sty
1535 texlive-latex-base: /usr/share/texlive/texmf-dist/tex/latex/graphics/color.sty
1536 endnotes.sty
1537 texlive-latex-extra: /usr/share/texlive/texmf-dist/tex/latex/endnotes/endnotes.sty
1538 fancyhdr.sty
1539 texlive-latex-base: /usr/share/texlive/texmf-dist/tex/latex/fancyhdr/fancyhdr.sty
1540 fontspec.sty
1541 texlive-latex-recommended: /usr/share/texlive/texmf-dist/tex/latex/fontspec/fontspec.sty
1542 footmisc.sty
1543 texlive-latex-extra: /usr/share/texlive/texmf-dist/tex/latex/footmisc/footmisc.sty
1544 graphicx.sty
1545 texlive-latex-base: /usr/share/texlive/texmf-dist/tex/latex/graphics/graphicx.sty
1546 inputenc.sty
1547 texlive-latex-base: /usr/share/texlive/texmf-dist/tex/latex/base/inputenc.sty
1548 listings.sty
1549 texlive-latex-recommended: /usr/share/texlive/texmf-dist/tex/latex/listings/listings.sty
1550 longtable.sty
1551 texlive-latex-base: /usr/share/texlive/texmf-dist/tex/latex/tools/longtable.sty
1552 manyfoot.sty
1553 texlive-latex-extra: /usr/share/texlive/texmf-dist/tex/latex/ncctools/manyfoot.sty
1554 mathptmx.sty
1555 texlive-font-utils: /usr/share/doc/texlive-doc/fonts/fontinst/examples/mathptmx/mathptmx.sty
1556 texlive-latex-base: /usr/share/texlive/texmf-dist/tex/latex/psnfss/mathptmx.sty
1557 multicol.sty
1558 ptex-jtex: /usr/share/texmf/ajtex/multicol.sty
1559 texlive-latex-base: /usr/share/texlive/texmf-dist/tex/latex/tools/multicol.sty
1560 parskip.sty
1561 texlive-latex-recommended: /usr/share/texlive/texmf-dist/tex/latex/parskip/parskip.sty
1562 polyglossia.sty
1563 texlive-latex-recommended: /usr/share/texlive/texmf-dist/tex/latex/polyglossia/polyglossia.sty
1564 soul.sty
1565 texlive-latex-extra: /usr/share/texlive/texmf-dist/tex/latex/soul/soul.sty
1566 textcomp.sty
1567 texlive-latex-base: /usr/share/texlive/texmf-dist/tex/latex/base/textcomp.sty
1568 thumbpdf.sty
1569 texlive-latex-recommended: /usr/share/texlive/texmf-dist/tex/generic/thumbpdf/thumbpdf.sty
1570 titlepic.sty
1571 texlive-latex-extra: /usr/share/texlive/texmf-dist/tex/latex/titlepic/titlepic.sty
1572 ucs.sty
1573 texlive-latex-extra: /usr/share/texlive/texmf-dist/tex/latex/ucs/ucs.sty
1574 ulem.sty
1575 texlive-plain-generic: /usr/share/texlive/texmf-dist/tex/generic/ulem/ulem.sty
1576 url.sty
1577 texlive-latex-base: /usr/share/texlive/texmf-dist/tex/latex/url/url.sty
1578 xeCJK.sty
1579 texlive-xetex: /usr/share/texlive/texmf-dist/tex/xelatex/xecjk/xeCJK.sty
1580 xltxtra.sty
1581 texlive-latex-recommended: /usr/share/texlive/texmf-dist/tex/latex/xltxtra/xltxtra.sty
1582 xunicode.sty
1583 texlive-latex-recommended: /usr/share/texlive/texmf-dist/tex/xelatex/xunicode/xunicode.sty
1584
1585 ** belongs to
1586
1587 texlive-base:
1588 amssymb.sty
1589 texlive-latex-base:
1590 alltt.sty
1591 babel.sty
1592 color.sty
1593 fancyhdr.sty
1594 graphicx.sty
1595 inputenc.sty
1596 longtable.sty
1597 mathptmx.sty
1598 multicol.sty
1599 textcomp.sty
1600 url.sty
1601 texlive-latex-extra:
1602 boites.sty
1603 breakurl.sty
1604 endnotes.sty
1605 footmisc.sty
1606 manyfoot.sty
1607 soul.sty
1608 titlepic.sty
1609 ucs.sty
1610 texlive-latex-recommended:
1611 fontspec.sty
1612 listings.sty
1613 parskip.sty
1614 polyglossia.sty
1615 thumbpdf.sty
1616 xltxtra.sty
1617 xunicode.sty
1618 texlive-plain-generic:
1619 ulem.sty
1620 texlive-xetex:
1621 xeCJK.sty
1622
1623 ** all texlive packages used
1624
1625 texlive-base
1626 texlive-latex-base
1627 texlive-latex-extra
1628 texlive-latex-recommended
1629 texlive-plain-generic
1630 texlive-xetex
1631