From 4d5ee2ead874c7a436faa8754eb99215927ea94d Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Sun, 27 Jun 2021 16:59:44 -0400 Subject: dir rename ./sundry (from ./misc) --- sundry/misc/util/rb/tex/dr_tex.rb | 120 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100755 sundry/misc/util/rb/tex/dr_tex.rb (limited to 'sundry/misc/util/rb/tex') diff --git a/sundry/misc/util/rb/tex/dr_tex.rb b/sundry/misc/util/rb/tex/dr_tex.rb new file mode 100755 index 0000000..b71d8c1 --- /dev/null +++ b/sundry/misc/util/rb/tex/dr_tex.rb @@ -0,0 +1,120 @@ +#!/usr/bin/env ruby +# /+ +# - Name: Spine, Doc Reform [a part of] +# - Description: documents, structuring, processing, publishing, search +# - static content generator +# +# - Author: Ralph Amissah +# [ralph.amissah@gmail.com] +# +# - Copyright: (C) 2015 - 2021 Ralph Amissah, All Rights +# Reserved. +# +# - License: AGPL 3 or later: +# +# Spine (SiSU), a framework for document structuring, publishing and +# search +# +# Copyright (C) Ralph Amissah +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU AFERO General Public License as published by the +# Free Software Foundation, either version 3 of the License, or (at your +# option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# this program. If not, see [https://www.gnu.org/licenses/]. +# +# If you have Internet connection, the latest version of the AGPL should be +# available at these locations: +# [https://www.fsf.org/licensing/licenses/agpl.html] +# [https://www.gnu.org/licenses/agpl.html] +# +# - Spine (by Doc Reform, related to SiSU) uses standard: +# - docReform markup syntax +# - standard SiSU markup syntax with modified headers and minor modifications +# - docReform object numbering +# - standard SiSU object citation numbering & system +# +# - Hompages: +# [https://www.doc_reform.org] +# [https://www.sisudoc.org] +# +# - Git +# [https://git.sisudoc.org/projects/?p=software/spine.git;a=summary] +# +# +/ +require 'fileutils' +pwd = Dir.pwd +argv,texfiles_with_path,flags=[],[],[] +lngs = %{(am|bg|bn|br|ca|cs|cy|da|de|el|en|eo|es|et|eu|fi|fr|ga|gl|he|hi|hr|hy|ia|is|it|ja|ko|la|lo|lt|lv|ml|mr|nl|no|nn|oc|pl|pt|pt_BR|ro|ru|sa|se|sk|sl|sq|sr|sv|ta|te|th|tk|tr|uk|ur|vi|zh)} +Regexp.new(lngs, Regexp::IGNORECASE) +argv=$* +argv.sort.each{|y| (y =~/^--\S+$/i) ? (flags << y) : (texfiles_with_path << y) } +if flags.length==0 \ +|| flags.inspect =~/"--help"/ + cmd=(/([^\/]+)$/).match($0)[1] + puts < 0 + texfiles_with_path.each do |texfile_with_path| + if texfile_with_path =~/.+\.tex/ + #puts texfile_with_path + if FileTest.file?(texfile_with_path) + file_basename_with_path = texfile_with_path.sub(/\.tex$/,'') + file_basename = file_basename_with_path.sub(/.*?([^\/]+)$/,'\1') + _out_path = out_path + if file_basename =~ /\.#{lngs}$/ + lng = file_basename.match(/\.#{lngs}$/)[1] + puts file_basename + puts lng + puts _out_path + unless _out_path.match(/\/#{lng}\/pdf$/) + _out_path = "#{out_path}/#{lng}/pdf" + FileUtils::mkdir_p(_out_path) + end + end + texpdf_cmd = %{xetex -interaction=batchmode -fmt=xelatex #{texfile_with_path}\n} + puts texpdf_cmd + 2.times { |i| system(texpdf_cmd) } + if (FileTest.file?(%{#{pwd}/#{file_basename}.pdf})) && (FileTest.directory?(_out_path)) + FileUtils::Verbose::mv(%{#{pwd}/#{file_basename}.pdf}, %{#{_out_path}/#{file_basename}.pdf}) + puts (%{#{_out_path}/#{file_basename}.pdf}) + else + puts "issue with pdf file or output directory" + puts "pdf file: #{pwd}/#{file_basename}.pdf}" + puts "output dir: #{_out_path}/" + end + suffix = ['log', 'out', 'toc', 'aux'] + suffix.each { |s| FileUtils::rm_f(%{#{pwd}/#{file_basename}.#{s}})} + end + end + end +end +Dir.chdir(pwd) +__END__ -- cgit v1.2.3