Last active
December 12, 2015 08:38
-
-
Save rinx/4745231 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin ruby | |
# -*- coding: utf-8 -*- | |
# ask file information | |
print("input filename: ") | |
filename = gets().chomp() | |
if (filename == "") then | |
filename = "lualatex-template.tex" | |
print("filename is default: #{filename}\n") | |
end | |
print("input documentclass: ") | |
dc_class = gets().chomp() | |
if (dc_class == "") then | |
dc_class = "ltjsarticle" | |
print("documentclass is default: #{dc_class}\n") | |
end | |
print("input topmargin[mm]: ") | |
topmargin = gets().chomp() | |
if (topmargin == "") then | |
topmargin = 4.6 | |
print("topmargin is default: #{topmargin + 25.4}\n") | |
else | |
topmargin = topmargin.to_f - 25.4 | |
end | |
print("input bottommargin[mm]: ") | |
bottommargin = gets().chomp() | |
if (bottommargin == "") then | |
bottommargin = 30 + topmargin + 25.4 | |
print("bottommargin is default: #{bottommargin - topmargin - 25.4}\n") | |
else | |
bottommargin = bottommargin.to_f + topmargin + 25.4 | |
end | |
print("input leftmargin[mm]: ") | |
leftmargin = gets().chomp() | |
if (leftmargin == "") then | |
leftmargin = 4.6 | |
print("leftmargin is default: #{leftmargin + 25.4}\n") | |
else | |
leftmargin = leftmargin.to_f - 25.4 | |
end | |
print("input rightmargin[mm]: ") | |
rightmargin = gets().chomp() | |
if (rightmargin == "") then | |
rightmargin = 30 + leftmargin + 25.4 | |
print("rightmargin is default: #{rightmargin - leftmargin - 25.4}\n") | |
else | |
rightmargin = rightmargin.to_f + leftmargin + 25.4 | |
end | |
print("input linestretch: ") | |
linestretch = gets().chomp() | |
if (linestretch == "") then | |
linestretch = 1.0 | |
print("linestretch is default: #{linestretch}\n") | |
else | |
linestretch = linestretch.to_f | |
end | |
# contents | |
temp = "\\documentclass{" + dc_class + "}\n\n" | |
temp += "\\setlength{\\textheight}{\\paperheight}\n" | |
temp += "\\setlength{\\topmargin}{#{topmargin}truemm}\n" | |
temp += "\\addtolength{\\topmargin}{-\\headheight}\n" | |
temp += "\\addtolength{\\topmargin}{-\\headsep}\n" | |
temp += "\\addtolength{\\textheight}{-#{bottommargin}truemm}\n\n" | |
temp += "\\setlength{\\textwidth}{\\paperwidth}\n" | |
temp += "\\setlength{\\oddsidemargin}{#{leftmargin}truemm}\n" | |
temp += "\\setlength{\\evensidemargin}{#{leftmargin}truemm}\n" | |
temp += "\\addtolength{\\textwidth}{-#{rightmargin}truemm}\n\n" | |
temp += "\\renewcommand{\\baselinestretch}{#{linestretch}}\n\n" | |
temp += "\\begin{document}\n\n\n" | |
temp += "\\end{document}\n" | |
# write | |
out_f = open(filename, "w") | |
out_f.write(temp) | |
out_f.close() | |
print("#{filename} was written. (encoding: utf-8)\n") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
lualatex用(UTF-8)余白テンプレート作成スクリプト。数値の扱いに注意