class SiSU_TeX::Source::LaTeXtoPdf
Public Class Methods
new(md,env)
click to toggle source
# File lib/sisu/texpdf.rb, line 181 def initialize(md,env) @md,@env=md,env @f=SiSU_Env::FileOp.new(@md).base_filename end
Public Instance Methods
latex_do(texfilename,papersize)
click to toggle source
# File lib/sisu/texpdf.rb, line 185 def latex_do(texfilename,papersize) @texfilename=texfilename @@n_lpdf=@@n_lpdf+1 tex_fn_base=@texfilename.gsub(/\.tex$/,'') tell=SiSU_Screen::Ansi.new(@md.opt.selections.str) if @md.opt.act[:pdf_p][:set]==:on if (@md.opt.act[:verbose][:set]==:on \ || @md.opt.act[:verbose_plus][:set]==:on \ || @md.opt.act[:maintenance][:set]==:on) SiSU_Screen::Ansi.new( @md.opt.act[:color_state][:set], "#{papersize} portrait ->" ).dark_grey_title_hi end cmd=SiSU_Env::SystemCall.new("#{tex_fn_base}.tex",'',@md.opt.selections.str) if @md.opt.act[:verbose][:set]==:on \ || @md.opt.act[:verbose_plus][:set]==:on \ || @md.opt.act[:maintenance][:set]==:on tell.grey_open end if "#{tex_fn_base}" =~/\w+/ \ and "#{papersize}" =~/\w+/ 2.times { |i| cmd.latex2pdf(@md,papersize) } #comment out to skip processing of latex portrait end if @md.opt.act[:verbose][:set]==:on \ || @md.opt.act[:verbose_plus][:set]==:on \ || @md.opt.act[:maintenance][:set]==:on tell.p_off end end if @md.opt.act[:pdf_l][:set]==:on if (@md.opt.act[:verbose][:set]==:on \ || @md.opt.act[:verbose_plus][:set]==:on \ || @md.opt.act[:maintenance][:set]==:on) SiSU_Screen::Ansi.new( @md.opt.act[:color_state][:set], "#{papersize} landscape ->" ).dark_grey_title_hi end cmd=SiSU_Env::SystemCall.new("#{tex_fn_base}.landscape.tex",'',@md.opt.selections.str) if (@md.opt.act[:verbose][:set]==:on \ || @md.opt.act[:verbose_plus][:set]==:on \ || @md.opt.act[:maintenance][:set]==:on) tell.grey_open end if "#{tex_fn_base}" =~/\w+/ \ and "#{papersize}" =~/\w+/ 2.times { |i| cmd.latex2pdf(@md,papersize) } #comment out to skip processing of latex landscape end if (@md.opt.act[:verbose][:set]==:on \ || @md.opt.act[:verbose_plus][:set]==:on \ || @md.opt.act[:maintenance][:set]==:on) tell.p_off end end pwd=Dir.pwd 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/ then pdf_p=@f.pdf_p_a4; pdf_l=@f.pdf_l_a4 when /a5/ then pdf_p=@f.pdf_p_a5; pdf_l=@f.pdf_l_a5 when /b5/ then pdf_p=@f.pdf_p_b5; pdf_l=@f.pdf_l_b5 when /letter/ then pdf_p=@f.pdf_p_letter; pdf_l=@f.pdf_l_letter when /legal/ then 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 FileUtils::mkdir_p(@md.file.output_path.pdf.dir) unless FileTest.directory?(@md.file.output_path.pdf.dir) cX=SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set]).cX 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 STDERR.puts "#{__FILE__}:#{__LINE__} NOT FOUND: #{portrait_pdf}" if @md.opt.act[:maintenance][:set]==:on errmsg="pdf file not generated #{portrait_pdf.gsub(/.+?([^\/]+?\.pdf)$/,'\1')} (check texlive dependencies)" if @md.opt.act[:no_stop][:set]==:on SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia). error("#{errmsg}, proceeding without pdf output (as requested)") else SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia). error("#{errmsg}, STOPPING") exit end end end 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 STDERR.puts "#{__FILE__}:#{__LINE__} NOT FOUND: #{landscape_pdf}" if @md.opt.act[:maintenance][:set]==:on errmsg="pdf file not generated #{landscape_pdf.gsub(/.+?([^\/]+?\.pdf)$/,'\1')} (check texlive dependencies)" if @md.opt.act[:no_stop][:set]==:on SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia). error("#{errmsg}, proceeding without pdf output (as requested)") else SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia). error("#{errmsg}, STOPPING") exit end end end if (@md.opt.act[:verbose][:set]==:on \ || @md.opt.act[:verbose_plus][:set]==:on \ || @md.opt.act[:maintenance][:set]==:on) SiSU_Screen::Ansi.new( @md.opt.act[:color_state][:set], @@n_lpdf, 'processed (SiSU LaTeX to pdf - using pdfetex aka. pdftex or pdflatex)' ).generic_number end end
latexrun_selective()
click to toggle source
# File lib/sisu/texpdf.rb, line 301 def latexrun_selective begin pwd=Dir.pwd Dir.chdir(pwd) #watch @tex_f_no=0 if FileTest.file?(@env.source_file_with_path) @md.papersize_array.each do |ps| if @md.fns =~/\.(?:-|ssm\.)?sst$/ case @md.fns when /\.(?:-|ssm\.)?sst$/ if FileTest.directory?(@env.processing_path.tex)==true Dir.chdir(@env.processing_path.tex) texfile=@md.fns.gsub(/$/,".#{ps}.tex"). gsub(/~/,'-') if @md.opt.act[:pdf_p][:set]==:on \ or @md.opt.act[:pdf_l][:set]==:on latex_do(texfile,ps) if @md.opt.act[:pdf_p][:set]==:on if File.exist?(texfile) \ and File.size(texfile) > 0 #@tex_f_no+=1 else errmsg="zero file size #{@env.processing_path.tex}/#{texfile}" if @md.opt.act[:no_stop][:set]==:on SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia). error("#{errmsg}, proceeding without pdf output (as requested)") else SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia). error("#{errmsg}, STOPPING") exit end end end end end end end end case @md.papersize_array[0] #default pdf when /a4/ then pdf_p=@f.pdf_p_a4; pdf_l=@f.pdf_l_a4 when /a5/ then pdf_p=@f.pdf_p_a5; pdf_l=@f.pdf_l_a5 when /b5/ then pdf_p=@f.pdf_p_b5; pdf_l=@f.pdf_l_b5 when /letter/ then pdf_p=@f.pdf_p_letter; pdf_l=@f.pdf_l_letter when /legal/ then 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 @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 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_l, mklnk) Dir.chdir(pwd_set) end end else SiSU_Screen::Ansi.new( @md.opt.act[:color_state][:set], "*WARN* FILE NOT FOUND: << #{@md.fns} >> - requested latex system processing skipped" ).warn end lst=Dir["*.{aux,log,out}"] lst.each {|file| File.unlink(file)} if lst rescue SiSU_Errors::Rescued.new($!,$@,@md.opt.selections.str,@md.fns).location do __LINE__.to_s + ':' + __FILE__ end end end