aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sisu/v4/texpdf.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sisu/v4/texpdf.rb')
-rw-r--r--lib/sisu/v4/texpdf.rb278
1 files changed, 173 insertions, 105 deletions
diff --git a/lib/sisu/v4/texpdf.rb b/lib/sisu/v4/texpdf.rb
index 20998e6c..34d4f69c 100644
--- a/lib/sisu/v4/texpdf.rb
+++ b/lib/sisu/v4/texpdf.rb
@@ -109,8 +109,12 @@ module SiSU_TeX
SiSU_Screen::Ansi.new(@opt.cmd,'LaTeX/PDF',"[#{@opt.f_pth[:lng_is]}] #{@opt.fno}").green_title_hi unless @opt.cmd =~/q/
if @opt.cmd =~/[MVv]/
path=@env.url.output_tell
- SiSU_Screen::Ansi.new(@opt.cmd,@opt.fns,"#{@env.program.pdf_viewer} #{@md.file.output_path.pdf.dir}/#{@md.file.base_filename.pdf_l}pdf").flow
- SiSU_Screen::Ansi.new(@opt.cmd,@opt.fns,"#{@opt.fns} #{@env.program.pdf_viewer} #{@md.file.output_path.pdf.dir}/#{@md.file.base_filename.pdf_p}pdf").flow
+ if @md.opt.act[:pdf_l][:set]==:on
+ SiSU_Screen::Ansi.new(@opt.cmd,@opt.fns,"#{@env.program.pdf_viewer} #{@md.file.output_path.pdf.dir}/#{@md.file.base_filename.pdf_l}pdf").flow
+ end
+ if @md.opt.act[:pdf_p][:set]==:on
+ SiSU_Screen::Ansi.new(@opt.cmd,@opt.fns,"#{@opt.fns} #{@env.program.pdf_viewer} #{@md.file.output_path.pdf.dir}/#{@md.file.base_filename.pdf_p}pdf").flow
+ end
end
@md=@particulars.md
$flag=@md.opt.cmd #introduced to pass 0 for no object citation numbers... to texpdf_format
@@ -157,27 +161,35 @@ module SiSU_TeX
def latex_do(texfilename,papersize)
@texfilename=texfilename
@@n_lpdf=@@n_lpdf+1
- SiSU_Screen::Ansi.new(@md.opt.cmd,"#{papersize} portrait ->").dark_grey_title_hi if @md.opt.cmd =~/[MVv]/
tex_fn_base=@texfilename.gsub(/\.tex$/,'')
- cmd=SiSU_Env::SystemCall.new("#{tex_fn_base}.tex",'',@md.opt.cmd)
tell=SiSU_Screen::Ansi.new(@md.opt.cmd)
- tell.grey_open if @md.opt.cmd =~/[MVv]/
- if "#{tex_fn_base}" =~/\w+/ \
- and "#{papersize}" =~/\w+/
- 2.times { |i| cmd.latex2pdf(@md,papersize) } #comment out to skip processing of latex portrait
- end
- tell.p_off if @md.opt.cmd =~/[MVv]/
- SiSU_Screen::Ansi.new(@md.opt.cmd,"#{papersize} landscape ->").dark_grey_title_hi if @md.opt.cmd =~/[MVv]/
- cmd=SiSU_Env::SystemCall.new("#{tex_fn_base}.landscape.tex",'',@md.opt.cmd)
- tell.grey_open if @md.opt.cmd =~/[MVv]/
- if "#{tex_fn_base}" =~/\w+/ \
- and "#{papersize}" =~/\w+/
- 2.times { |i| cmd.latex2pdf(@md,papersize) } #comment out to skip processing of latex landscape
- end
- tell.p_off if @md.opt.cmd =~/[MVv]/
+ if @md.opt.act[:pdf_p][:set]==:on
+ SiSU_Screen::Ansi.new(@md.opt.cmd,"#{papersize} portrait ->").dark_grey_title_hi if @md.opt.cmd =~/[MVv]/
+ cmd=SiSU_Env::SystemCall.new("#{tex_fn_base}.tex",'',@md.opt.cmd)
+ tell.grey_open if @md.opt.cmd =~/[MVv]/
+ if "#{tex_fn_base}" =~/\w+/ \
+ and "#{papersize}" =~/\w+/
+ 2.times { |i| cmd.latex2pdf(@md,papersize) } #comment out to skip processing of latex portrait
+ end
+ tell.p_off if @md.opt.cmd =~/[MVv]/
+ end
+ if @md.opt.act[:pdf_l][:set]==:on
+ SiSU_Screen::Ansi.new(@md.opt.cmd,"#{papersize} landscape ->").dark_grey_title_hi if @md.opt.cmd =~/[MVv]/
+ cmd=SiSU_Env::SystemCall.new("#{tex_fn_base}.landscape.tex",'',@md.opt.cmd)
+ tell.grey_open if @md.opt.cmd =~/[MVv]/
+ if "#{tex_fn_base}" =~/\w+/ \
+ and "#{papersize}" =~/\w+/
+ 2.times { |i| cmd.latex2pdf(@md,papersize) } #comment out to skip processing of latex landscape
+ end
+ tell.p_off if @md.opt.cmd =~/[MVv]/
+ end
pwd=Dir.pwd
- portrait_pdf="#{pwd}/#{tex_fn_base}.pdf"
- landscape_pdf="#{pwd}/#{tex_fn_base}.landscape.pdf"
+ if @md.opt.act[:pdf_p][:set]==:on
+ portrait_pdf="#{pwd}/#{tex_fn_base}.pdf"
+ end
+ if @md.opt.act[:pdf_l][:set]==:on
+ landscape_pdf="#{pwd}/#{tex_fn_base}.landscape.pdf"
+ end
case papersize
when /a4/; pdf_p=@f.pdf_p_a4; pdf_l=@f.pdf_l_a4
when /a5/; pdf_p=@f.pdf_p_a5; pdf_l=@f.pdf_l_a5
@@ -187,15 +199,19 @@ module SiSU_TeX
else pdf_p=@f.pdf_p_a4; pdf_l=@f.pdf_l_a4
end
FileUtils::mkdir_p(@md.file.output_path.pdf.dir) unless FileTest.directory?(@md.file.output_path.pdf.dir)
- if FileTest.file?(portrait_pdf)
- FileUtils::cp(portrait_pdf,"#{@md.file.output_path.pdf.dir}/#{pdf_p}")
- FileUtils::rm(portrait_pdf)
- else p "#{__FILE__}:#{__LINE__} NOT FOUND: #{portrait_pdf}" if @md.opt.cmd.inspect =~/M/
+ if @md.opt.act[:pdf_p][:set]==:on
+ if FileTest.file?(portrait_pdf)
+ FileUtils::cp(portrait_pdf,"#{@md.file.output_path.pdf.dir}/#{pdf_p}")
+ FileUtils::rm(portrait_pdf)
+ else p "#{__FILE__}:#{__LINE__} NOT FOUND: #{portrait_pdf}" if @md.opt.cmd.inspect =~/M/
+ end
end
- if FileTest.file?(landscape_pdf)
- FileUtils::cp(landscape_pdf,"#{@md.file.output_path.pdf.dir}/#{pdf_l}")
- FileUtils::rm(landscape_pdf)
- else p "#{__FILE__}:#{__LINE__} NOT FOUND: #{landscape_pdf}" if @md.opt.cmd.inspect =~/M/
+ if @md.opt.act[:pdf_l][:set]==:on
+ if FileTest.file?(landscape_pdf)
+ FileUtils::cp(landscape_pdf,"#{@md.file.output_path.pdf.dir}/#{pdf_l}")
+ FileUtils::rm(landscape_pdf)
+ else p "#{__FILE__}:#{__LINE__} NOT FOUND: #{landscape_pdf}" if @md.opt.cmd.inspect =~/M/
+ end
end
SiSU_Screen::Ansi.new(@md.opt.cmd,@@n_lpdf,'processed (SiSU LaTeX to pdf - using pdfetex aka. pdftex or pdflatex)').generic_number if @md.opt.cmd =~/[MVv]/
end
@@ -214,13 +230,18 @@ module SiSU_TeX
Dir.chdir(@env.processing_path.tex)
texfile=@md.fns.gsub(/$/,".#{ps}.tex").
gsub(/~/,'-')
- if File.exist?(texfile) \
- and File.size(texfile) > 0
- @tex_f_no+=1
- #p "#{__FILE__}:#{__LINE__} texpdf generation disabled" if @md.opt.cmd.inspect =~/M/ #%% disable temporarily, re-enable
+ if @md.opt.act[:pdf_p][:set]==:on \
+ or @md.opt.act[:pdf_l][:set]==:on
latex_do(texfile,ps)
- else
- puts "\tzero file size #{@env.processing_path.tex}/#{texfile}"
+ if @md.opt.act[:pdf_p][:set]==:on
+ if File.exist?(texfile) \
+ and File.size(texfile) > 0
+ #@tex_f_no+=1
+ else
+ puts SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).set(:fuchsia)
+ puts "\tzero file size #{@env.processing_path.tex}/#{texfile}"
+ end
+ end
end
end
end
@@ -234,32 +255,34 @@ module SiSU_TeX
when /legal/; pdf_p=@f.pdf_p_legal; pdf_l=@f.pdf_l_legal
else pdf_p=@f.pdf_p_a4; pdf_l=@f.pdf_l_a4
end
- if FileTest.file?("#{@md.file.output_path.pdf.dir}/#{pdf_p}")
- mklnk=if @md.file.output_dir_structure.by_language_code? \
- or @md.file.output_dir_structure.by_filetype?
- "#{@md.fnb}.portrait.pdf"
- else 'portrait.pdf'
+ if @md.opt.act[:pdf_p][:set]==:on
+ if FileTest.file?("#{@md.file.output_path.pdf.dir}/#{pdf_p}")
+ mklnk=((@md.file.output_dir_structure.by_language_code?) \
+ || (@md.file.output_dir_structure.by_filetype?)) \
+ ? "#{@md.fnb}.portrait.pdf"
+ : 'portrait.pdf'
+ if FileTest.directory?(@md.file.output_path.pdf.dir)
+ pwd=Dir.pwd
+ Dir.chdir(@md.file.output_path.pdf.dir)
+ FileUtils::rm_f(mklnk)
+ FileUtils::ln_s(pdf_p, mklnk)
+ Dir.chdir(pwd)
+ end
end
- if FileTest.directory?(@md.file.output_path.pdf.dir)
- pwd=Dir.pwd
+ end
+ if @md.opt.act[:pdf_l][:set]==:on
+ if FileTest.file?("#{@md.file.output_path.pdf.dir}/#{pdf_l}")
+ mklnk=((@md.file.output_dir_structure.by_language_code?) \
+ || (@md.file.output_dir_structure.by_filetype?)) \
+ ? "#{@md.fnb}.landscape.pdf"
+ : 'landscape.pdf'
+ pwd_set=Dir.pwd
Dir.chdir(@md.file.output_path.pdf.dir)
FileUtils::rm_f(mklnk)
- FileUtils::ln_s(pdf_p, mklnk)
- Dir.chdir(pwd)
+ FileUtils::ln_s(pdf_l, mklnk)
+ Dir.chdir(pwd_set)
end
end
- if FileTest.file?("#{@md.file.output_path.pdf.dir}/#{pdf_l}")
- mklnk=if @md.file.output_dir_structure.by_language_code? \
- or @md.file.output_dir_structure.by_filetype?
- "#{@md.fnb}.landscape.pdf"
- else 'landscape.pdf'
- end
- pwd_set=Dir.pwd
- Dir.chdir(@md.file.output_path.pdf.dir)
- FileUtils::rm_f(mklnk)
- FileUtils::ln_s(pdf_l, mklnk)
- Dir.chdir(pwd_set)
- end
else
SiSU_Screen::Ansi.new(@md.opt.cmd,"*WARN* FILE NOT FOUND: << #{@md.fns} >> - requested latex system processing skipped").warn
end
@@ -303,7 +326,18 @@ module SiSU_TeX
data=@data
@@tex_footnote_array=[]
@@rights=nil
- SiSU_Screen::Ansi.new(@md.opt.cmd,"pdfTex portrait & landscape").txt_grey if @md.opt.cmd=~/[MVvz]/
+ txt_gen=if @md.opt.act[:pdf_l][:set]==:on \
+ and @md.opt.act[:pdf_p][:set]==:on
+ 'pdfTex portrait & landscape'
+ elsif @md.opt.act[:pdf_l][:set]==:on
+ 'pdfTex landscape'
+ elsif @md.opt.act[:pdf_p][:set]==:on
+ 'pdfTex portrait'
+ else
+ puts SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).set(:fuchsia)
+ 'error: neither landscape nor portrait'
+ end
+ SiSU_Screen::Ansi.new(@md.opt.cmd,txt_gen).txt_grey if @md.opt.cmd=~/[MVvz]/
if defined? @md.rights.all \
and not @md.rights.all.empty?
rght=@md.rights #.author.dup #dup is necessary, else contents of :rights changed
@@ -671,12 +705,16 @@ module SiSU_TeX
home=@vz.txt_home.gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}|#{Mx[:br_paragraph]}|\\\\/,' - ') #no line splitting in heading neither html nor latex
title=@md.title.full.gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}|#{Mx[:br_paragraph]}|\\\\/,' - ') #no line splitting in heading neither html nor latex
@md.papersize_array.each do |ps|
- txt_obj={ txt: "#{home}: - #{title}", paper_size: ps, orientation: 'portrait' }
- orient_portrait=SiSU_TeX_Pdf::FormatHead.new(@md,txt_obj)
- txt_obj={ txt: "#{home}: - #{title}", paper_size: ps, orientation: 'landscape' }
- orient_landscape=SiSU_TeX_Pdf::FormatHead.new(@md,txt_obj)
- @@tex_head[ps][:p]=orient_portrait.document_head_with_orientation(@codeblock_box)
- @@tex_head[ps][:l]=orient_landscape.document_head_with_orientation(@codeblock_box)
+ if @md.opt.act[:pdf_p][:set]==:on
+ txt_obj={ txt: "#{home}: - #{title}", paper_size: ps, orientation: 'portrait' }
+ orient_portrait=SiSU_TeX_Pdf::FormatHead.new(@md,txt_obj)
+ @@tex_head[ps][:p]=orient_portrait.document_head_with_orientation(@codeblock_box)
+ end
+ if @md.opt.act[:pdf_l][:set]==:on
+ txt_obj={ txt: "#{home}: - #{title}", paper_size: ps, orientation: 'landscape' }
+ orient_landscape=SiSU_TeX_Pdf::FormatHead.new(@md,txt_obj)
+ @@tex_head[ps][:l]=orient_landscape.document_head_with_orientation(@codeblock_box)
+ end
end
@tex_file <<<<-WOK
#{@tex_ml.header}#{@tex_ml.footer}
@@ -715,8 +753,12 @@ module SiSU_TeX
@copymark='' #check and remove as now is superflous
x={}
txt_obj={ title: @md.title.full }
- x[:l]=SiSU_TeX_Pdf::FormatTextObject.new(@md,txt_obj).title_landscape
- x[:p]=SiSU_TeX_Pdf::FormatTextObject.new(@md,txt_obj).title_portrait
+ if @md.opt.act[:pdf_l][:set]==:on
+ x[:l]=SiSU_TeX_Pdf::FormatTextObject.new(@md,txt_obj).title_landscape
+ end
+ if @md.opt.act[:pdf_p][:set]==:on
+ x[:p]=SiSU_TeX_Pdf::FormatTextObject.new(@md,txt_obj).title_portrait
+ end
@tex_file << x
x=nil
if defined? @md.creator.author \
@@ -901,59 +943,77 @@ module SiSU_TeX
def output_morph_hash(o)
ps,h,fn=o[:ps],o[:h],o[:filename]
if h[ps] \
- and (h[ps][:p] and h[ps][:l])
- if h[ps][:p]
- h[ps][:p]=h[ps][:p].gsub(/[ ]+$/m,'').
- gsub(/\n\n\n+/m,"\n\n")
- end
- if h[ps][:l]
- h[ps][:l]=h[ps][:l].gsub(/[ ]+$/m,'').
- gsub(/\n\n\n+/m,"\n\n")
- end
- #h[ps][:p].gsub!(/(?:^[ ]+|[ ]+$)/m,'') if h[ps][:p]
- #h[ps][:l].gsub!(/(?:^[ ]+|[ ]+$)/m,'') if h[ps][:l]
- if h[ps][:p] !~/\A\s*\Z/
- fn[:portrait].puts h[ps][:p],"\n"
- end
- if h[ps][:l] !~/\A\s*\Z/
- fn[:landscape].puts h[ps][:l],"\n"
- end
- elsif (h[:p] and h[:l])
- if h[:p]
- h[:p]=h[:p].gsub(/[ ]+$/m,'').
- gsub(/\n\n\n+/m,"\n\n")
+ and (h[ps][:p] or h[ps][:l])
+ if @md.opt.act[:pdf_p][:set]==:on
+ if h[ps][:p]
+ h[ps][:p]=h[ps][:p].gsub(/[ ]+$/m,'').
+ gsub(/\n\n\n+/m,"\n\n")
+ end
+ if h[ps][:p] !~/\A\s*\Z/
+ fn[:portrait].puts h[ps][:p],"\n"
+ end
end
- if h[:l]
- h[:l]=h[:l].gsub(/[ ]+$/m,'').
- gsub(/\n\n\n+/m,"\n\n")
+ if @md.opt.act[:pdf_l][:set]==:on
+ if h[ps][:l]
+ h[ps][:l]=h[ps][:l].gsub(/[ ]+$/m,'').
+ gsub(/\n\n\n+/m,"\n\n")
+ end
+ if h[ps][:l] !~/\A\s*\Z/
+ fn[:landscape].puts h[ps][:l],"\n"
+ end
end
- #h[:p].gsub!(/(?:^[ ]+|[ ]+$)/m,'') if h[:p]
- #h[:l].gsub!(/(?:^[ ]+|[ ]+$)/m,'') if h[:l]
- if h[:p] !~/\A\s*\Z/
- fn[:portrait].puts h[:p],"\n"
+ elsif (h[:p] or h[:l])
+ if @md.opt.act[:pdf_p][:set]==:on
+ if h[:p]
+ h[:p]=h[:p].gsub(/[ ]+$/m,'').
+ gsub(/\n\n\n+/m,"\n\n")
+ end
+ if h[:p] !~/\A\s*\Z/
+ fn[:portrait].puts h[:p],"\n"
+ end
end
- if h[:l] !~/\A\s*\Z/
- fn[:landscape].puts h[:l],"\n"
+ if @md.opt.act[:pdf_l][:set]==:on
+ if h[:l]
+ h[:l]=h[:l].gsub(/[ ]+$/m,'').
+ gsub(/\n\n\n+/m,"\n\n")
+ end
+ if h[:l] !~/\A\s*\Z/
+ fn[:landscape].puts h[:l],"\n"
+ end
end
else p "#{__FILE__}:#{__LINE__}" if @md.opt.cmd.inspect =~/M/
end
end
def output(array)
@array=array=array.flatten.compact
- fns_l=@md.fns.gsub(/~/,'-') #this is a sorry fix, but necessary as it appears latex programs like not ~
+ fns=@md.fns.gsub(/~/,'-') #this is a sorry fix, but necessary as it appears latex programs like not ~
@md.papersize_array.each do |ps|
+ texfile_landscape=(@md.opt.act[:pdf_l][:set]==:on) \
+ ? (File.new("#{@env.processing_path.tex}/#{fns}.#{ps}.landscape.tex",'w+'))
+ : nil
+ texfile_portrait=(@md.opt.act[:pdf_p][:set]==:on) \
+ ? (File.new("#{@env.processing_path.tex}/#{fns}.#{ps}.tex",'w+'))
+ : nil
file={
- landscape: File.new("#{@env.processing_path.tex}/#{fns_l}.#{ps}.landscape.tex",'w+'),
- portrait: File.new("#{@env.processing_path.tex}/#{fns_l}.#{ps}.tex",'w+')
+ landscape: texfile_landscape,
+ portrait: texfile_portrait
}
- file[:portrait] << @@tex_head[ps][:p]
- file[:landscape] << @@tex_head[ps][:l]
+ if @md.opt.act[:pdf_p][:set]==:on
+ file[:portrait] << @@tex_head[ps][:p]
+ end
+ if @md.opt.act[:pdf_l][:set]==:on
+ file[:landscape] << @@tex_head[ps][:l]
+ end
array.each do |morph|
if morph.is_a?(String)
#morph.gsub!(/^\s+/,'')
if morph !~/\A\s*\Z/
- file[:portrait].puts morph,"\n"
- file[:landscape].puts morph,"\n"
+ if @md.opt.act[:pdf_p][:set]==:on
+ file[:portrait].puts morph,"\n"
+ end
+ if @md.opt.act[:pdf_l][:set]==:on
+ file[:landscape].puts morph,"\n"
+ end
end
elsif morph.class.inspect =~ /SiSU_DAL_DocumentStructure/ \
and morph.tmp \
@@ -965,8 +1025,12 @@ module SiSU_TeX
end
if (morph.tmp !~/\A\s*\Z/) \
|| morph.is==:code
- file[:portrait].puts morph.tmp,"\n"
- file[:landscape].puts morph.tmp,"\n"
+ if @md.opt.act[:pdf_p][:set]==:on
+ file[:portrait].puts morph.tmp,"\n"
+ end
+ if @md.opt.act[:pdf_l][:set]==:on
+ file[:landscape].puts morph.tmp,"\n"
+ end
end
elsif morph.is_a?(Hash) #inserted headers and the like, only
h={ ps: ps, h: morph, filename: file }
@@ -977,8 +1041,12 @@ module SiSU_TeX
end
end
array=@array
- file[:portrait].close
- file[:landscape].close
+ if @md.opt.act[:pdf_p][:set]==:on
+ file[:portrait].close
+ end
+ if @md.opt.act[:pdf_l][:set]==:on
+ file[:landscape].close
+ end
end
@@tex_head={
'a4'=> { p: nil, l: nil },