diff --git a/TufteBook.scriv.zip b/TufteBook.scriv.zip new file mode 100644 index 0000000..5115db9 Binary files /dev/null and b/TufteBook.scriv.zip differ diff --git a/sample-output/QuartoBook.pdf b/sample-output/QuartoBook.pdf new file mode 100644 index 0000000..a017a22 Binary files /dev/null and b/sample-output/QuartoBook.pdf differ diff --git a/sample-output/TufteBook.pdf b/sample-output/TufteBook.pdf new file mode 100644 index 0000000..47e7406 Binary files /dev/null and b/sample-output/TufteBook.pdf differ diff --git a/typst-run.rb b/typst-run.rb new file mode 100755 index 0000000..918ee1a --- /dev/null +++ b/typst-run.rb @@ -0,0 +1,156 @@ +#!/usr/bin/env ruby +# encoding: utf-8 + +# This script rewrites markdown compiled from Scrivener to be compatible +# with the cross-referencing system used by Typst. It also adds paths for +# LaTeX, python and others so that compilation works directly from Scrivener +# (Scrivener doesn't use the user's environment or path by default). +# Version: 0.1.0 + +Encoding.default_external = Encoding::UTF_8 +Encoding.default_internal = Encoding::UTF_8 + +require 'tempfile' # temp file tools +require 'fileutils' # ruby standard library to deal with files +#require 'debug/open_nonstop' # debugger, use binding.break to stop + +def makePath() # this method augments our environment path + home = ENV['HOME'] + '/' + envpath = '' + pathtest = [home+'.rbenv/shims', home+'.pyenv/shims', '/opt/homebrew/bin', '/usr/local/bin', + '/usr/local/opt/ruby/bin', '/usr/local/lib/ruby/gems/2.7.0/bin', + home+'Library/TinyTeX/bin/universal-darwin', '/Library/TeX/texbin', + home+'anaconda/bin', home+'anaconda3/bin', home+'miniconda/bin', home+'miniconda3/bin', + home+'micromamba/bin', home+'.cabal/bin', home+'.local/bin'] + pathtest.each { |p| envpath = envpath + ':' + p if File.directory?(p) } + envpath.gsub!(/\/{2}/, '/') + envpath.gsub!(/:{2}/, ':') + envpath.gsub!(/(^:|:$)/, '') + ENV['PATH'] = envpath + ':' + ENV['PATH'] + ENV['LANG'] = 'en_GB.UTF-8' if ENV['LANG'].nil? # Just in case we have no LANG, which breaks UTF8 encoding + puts "--> Modified path: #{ENV['PATH'].chomp}" + lap = ENV['HOME'] + '/.local/share/pandoc/custom/lapreprint.typ' + if File.exist?(lap) + puts "--> Copied #{lap} to current directory" + FileUtils.cp(lap, './') + end +end # end makePath() + +def isRecent(infile) # checks if a file is less than 3 minutes old + return false if !File.file?(infile) + filetime = File.mtime(infile) # modified time + difftime = Time.now - filetime # compare to now + if difftime <= 180 + return true + else + return false + end +end + +tstart = Time.now +infilename = File.expand_path(ARGV[0]) +puts "--> Input Filename: #{infilename}" +fail "The specified file does not exist!" unless infilename and File.file?(infilename) + +defType = ARGV[1] +if defType.nil? + defType = 'lapreprint' +end + +#binding.break + +makePath() +outfilename = infilename.gsub(/\.[q]?md$/,"-typst.md") # output to [name].md +outfilename2 = infilename.gsub(/\.[q]?md$/,"-typst.typ") # output to [name].typ +outfilename3 = infilename.gsub(/\.[q]?md$/,"-typst2.typ") # output to [name].typ +tfile = Tempfile.new('fix-x-refs') # create a temp file +lineSeparator = "\n" + +begin + File.open(infilename, 'r') do |file| + text = file.read + + # replace any ${USERHOME} with the user's home directory + text.gsub!(/\${USERHOME}\//, ENV['HOME']+'/') + + # cosmetic only: remove long runs (4 or more) of newlines + text.gsub!(/\n{4,}/,"\n\n") + + # This regex replaces @fig-… as a @reference + # otherwise Pandoc treats it as a citation + text.gsub!(/(@fig-\w+)/, "`\\1[Figure]`{=typst}") + + # This regex replaces @tbl-… as a @reference + # otherwise Pandoc treats it as a citation + text.gsub!(/(@tbl-\w+)/, "`\\1[Table]`{=typst}") + + # This regex replaces @eq-… as a @reference + # otherwise Pandoc treats it as a citation + text.gsub!(/(@eq-\w+)/, "`\\1[Equation]`{=typst}") + + # This regex replaces {#eq-} as a