fplatex 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 00759f874775732822b764a4e8e58a234769874a
4
+ data.tar.gz: 5527525895755b9f141f4d542c7f7d843c541c26
5
+ SHA512:
6
+ metadata.gz: ebfee34d140190875adfed11660a3622235c61a74627b1a84f35d25bbbd9ec34694745fc70e6a17c2bf24e98baeabea01a4e3b0ccc856b71fe51b39467c3988a
7
+ data.tar.gz: eeb8a99747d5c6f5e48819c02ca44abd783a60ff7411dd00f85f44ebf0525721c0b6f560041cb44f65c58409c66131430e1a8f9e986538cf833ae04512f6863a
data/bin/fplatex ADDED
@@ -0,0 +1,150 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'highline/import'
5
+ require 'fileutils'
6
+ require 'yaml'
7
+
8
+ class ScriptArguments < Hash
9
+ def initialize(args)
10
+ super()
11
+
12
+ opt_parser = OptionParser.new do |opts|
13
+ opts.banner = "Usage: fp_latex [options] \n If options aren't covered, script will ask for variables."
14
+
15
+ opts.on('-c COURSE', '--course', 'The course this assignment is for') do |course|
16
+ self[:course] = course
17
+ end
18
+
19
+ opts.on('-a AUTHOR', '--author', 'Your name') do |author|
20
+ self[:author] = author
21
+ end
22
+
23
+ opts.on('-t TITLE', '--title', 'Homework Assignment Name') do |title|
24
+ self[:title] = title
25
+ end
26
+
27
+ opts.on('-d DUEDATE', '--due-date', 'Due date of assignment') do |due_date|
28
+ self[:due_date] = due_date
29
+ end
30
+
31
+ opts.on('-p PROFESSOR', '--professor', 'The professor for the course') do |professor|
32
+ self[:professor] = professor
33
+ end
34
+
35
+ opts.on('-f FILENAME', '--filename', 'Desired filename of latex file, will append \'.tex\' if not already put. Uses relative paths.') do |filename|
36
+ self[:filename] = filename
37
+ end
38
+
39
+ opts.on('-y YAMLFILE', '--yaml-file',
40
+ 'Load a yaml file with all the variables set already. Must indicate which hash to use. For any missing variables, this script will ask for them if not specified by other flags.') do |yaml_file|
41
+ self[:yaml_file] = yaml_file
42
+ end
43
+
44
+ opts.on('-e PRESET', '--environment',
45
+ 'After choosing a yaml file, you must choose a preset set of variables. This is so you should only need one yaml file with all your variables and presets. Variables passed by flags override arguments from yaml file.') do |preset|
46
+ self[:preset] = preset
47
+ end
48
+
49
+ opts.on('-h', '--help', 'Display this help and exit') do
50
+ puts opts
51
+ exit
52
+ end
53
+ end
54
+
55
+ opt_parser.parse!(args)
56
+
57
+ end
58
+ end
59
+
60
+ arguments = ScriptArguments.new(ARGV)
61
+
62
+ class LatexVariables
63
+ def initialize(args)
64
+ @template_path = `gem which latex_hw_template.tex`
65
+ @template_path.slice!("\n")
66
+ if @template_path.empty?
67
+ puts "Can't find the latex template from the gem path, consider uninstalling and reinstalling"
68
+ exit
69
+ end
70
+
71
+ if args[:yaml_file] and File.exists?(args[:yaml_file])
72
+ config = YAML.load(File.new(args[:yaml_file]))
73
+ if args[:preset].nil? or config[args[:preset]].nil?
74
+ puts "If you're trying to use a YAML file to load variables you need to pass a valid preset hash as well."
75
+ exit
76
+ else
77
+ @filename = parse_filename(config[args[:preset]]['filename'])
78
+ @course = config[args[:preset]]['course']
79
+ @professor = config[args[:preset]]['professor']
80
+ @author = config[args[:preset]]['author']
81
+ @due_date = config[args[:preset]]['duedate']
82
+ @title = config[args[:preset]]['title']
83
+ end
84
+ end
85
+
86
+ if args[:filename]
87
+ @filename = parse_filename args[:filename]
88
+ if File.exists?(args[:filename])
89
+ confirm = ask("File named #{@filename} already exists, overwrite? [Y/N] ") { |yn| yn.limit = 1, yn.validate = /[yn]/i }
90
+ exit unless confirm.downcase == 'y'
91
+ else
92
+ system "cp #{@template_path} #{@filename}"
93
+ end
94
+ elsif !@filename
95
+ filename = ask("What would you like to name this latex file?")
96
+ @filename = parse_filename(filename)
97
+ FileUtils.cp("#{@template_path}", "#{@filename}")
98
+ end
99
+ if args[:course]
100
+ @course = args[:course]
101
+ elsif !@course
102
+ @course = ask("What course is this assignment for?")
103
+ end
104
+ if args[:professor]
105
+ @professor = args[:professor]
106
+ elsif !@professor
107
+ @professor = ask("What is the name of your professor?")
108
+ end
109
+ if args[:author]
110
+ @author = args[:author]
111
+ elsif !@author
112
+ @author = ask("Who are you?")
113
+ end
114
+ if args[:due_date]
115
+ @due_date = args[:due_date]
116
+ elsif !@due_date
117
+ @due_date = ask("When is this assignment due?")
118
+ end
119
+ if args[:title]
120
+ @title = args[:title]
121
+ elsif !@title
122
+ @title = ask("What is the title of this assignment?")
123
+ end
124
+
125
+ end
126
+
127
+ def parse_filename(filename)
128
+ if filename.nil? or filename.empty?
129
+ nil
130
+ elsif (filename =~ /^*\.$/i).nil?
131
+ filename + ".tex"
132
+ elsif (filename =~ /^*\.$/i)
133
+ filename + "tex"
134
+ else
135
+ filename
136
+ end
137
+ end
138
+
139
+ def execute
140
+ text = File.read(@filename)
141
+ new_text = text.gsub(/HOMEWORKTITLE/, @title).gsub(/DUEDATE/, @due_date).gsub(/COURSE/, @course).gsub(/PROFESSOR/, @professor).gsub(/AUTHOR/,@author)
142
+ File.write(@filename, new_text)
143
+ system "latex #{@filename}" if system "which latex"
144
+ system "pdflatex #{@filename}" if system "which pdflatex"
145
+ end
146
+
147
+ end
148
+
149
+ latex_variables = LatexVariables.new(arguments)
150
+ latex_variables.execute
Binary file
@@ -0,0 +1,155 @@
1
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
+ % Structured General Purpose Assignment
3
+ % LaTeX Template
4
+ %
5
+ % This template has been downloaded from:
6
+ % http://www.latextemplates.com
7
+ %
8
+ % Original author:
9
+ % Ted Pavlic (http://www.tedpavlic.com)
10
+ %
11
+ % Note:
12
+ % The \lipsum[#] commands throughout this template generate dummy text
13
+ % to fill the template out. These commands should all be removed when
14
+ % writing assignment content.
15
+ %
16
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17
+
18
+ %----------------------------------------------------------------------------------------
19
+ % PACKAGES AND OTHER DOCUMENT CONFIGURATIONS
20
+ %----------------------------------------------------------------------------------------
21
+
22
+ \documentclass{article}
23
+ \usepackage[numbered, framed]{matlab-prettifier}
24
+ \usepackage{amsmath}%
25
+ \usepackage{MnSymbol}%
26
+ \usepackage{wasysym}%
27
+ \usepackage{cancel}
28
+ \usepackage{tikz}
29
+ \usepackage{graphicx}
30
+ \usepackage[margin=1in]{geometry}
31
+ \usetikzlibrary{automata,positioning}
32
+ \usepackage{fancyhdr} % Required for custom headers
33
+ \usepackage{lastpage} % Required to determine the last page for the footer
34
+ \usepackage{extramarks} % Required for headers and footers
35
+ \usepackage{graphicx} % Required to insert images
36
+ \usepackage{lipsum} % Used for inserting dummy 'Lorem ipsum' text into the template
37
+ \usepackage{enumitem}
38
+ \usepackage{graphicx}
39
+ % Margins
40
+ \topmargin=-0.45in
41
+ \evensidemargin=0in
42
+ \oddsidemargin=0in
43
+ \textwidth=6.5in
44
+ \textheight=9.0in
45
+ \headsep=0.25in
46
+
47
+ \linespread{1.1} % Line spacing
48
+
49
+ % Set up the header and footer
50
+ \pagestyle{fancy}
51
+ \lhead{\hmwkAuthorName} % Top left header
52
+ \chead{\hmwkClass\ (\hmwkClassInstructor\ \hmwkClassTime): \hmwkTitle} % Top center header
53
+ \rhead{\firstxmark} % Top right header
54
+ \lfoot{\lastxmark} % Bottom left footer
55
+ \cfoot{} % Bottom center footer
56
+ \rfoot{Page\ \thepage\ of\ \pageref{LastPage}} % Bottom right footer
57
+ \renewcommand\headrulewidth{0.4pt} % Size of the header rule
58
+ \renewcommand\footrulewidth{0.4pt} % Size of the footer rule
59
+
60
+ %----------------------------------------------------------------------------------------
61
+ % DOCUMENT STRUCTURE COMMANDS
62
+ % Skip this unless you know what you're doing
63
+ %----------------------------------------------------------------------------------------
64
+
65
+ % Header and footer for when a page split occurs within a problem environment
66
+ \newcommand{\enterProblemHeader}[1]{
67
+ \nobreak\extramarks{#1}{#1 continued on next page\ldots}\nobreak
68
+ \nobreak\extramarks{#1 (continued)}{#1 continued on next page\ldots}\nobreak
69
+ }
70
+
71
+ % Header and footer for when a page split occurs between problem environments
72
+ \newcommand{\exitProblemHeader}[1]{
73
+ \nobreak\extramarks{#1 (continued)}{#1 continued on next page\ldots}\nobreak
74
+ \nobreak\extramarks{#1}{}\nobreak
75
+ }
76
+
77
+ \setcounter{secnumdepth}{0} % Removes default section numbers
78
+ \newcounter{homeworkProblemCounter} % Creates a counter to keep track of the number of problems
79
+
80
+ \newcommand{\homeworkProblemName}{}
81
+ \newenvironment{homeworkProblem}[1][Problem \arabic{homeworkProblemCounter}]{ % Makes a new environment called homeworkProblem which takes 1 argument (custom name) but the default is "Problem #"
82
+ \stepcounter{homeworkProblemCounter} % Increase counter for number of problems
83
+ \renewcommand{\homeworkProblemName}{#1} % Assign \homeworkProblemName the name of the problem
84
+ \section{\homeworkProblemName} % Make a section in the document with the custom problem count
85
+ \enterProblemHeader{} % Header and footer within the environment
86
+ }{
87
+ \exitProblemHeader{} % Header and footer after the environment
88
+ }
89
+
90
+ \newcommand{\problemAnswer}[1]{ % Defines the problem answer command with the content as the only argument
91
+ \noindent\framebox[\columnwidth][c]{\begin{minipage}{0.98\columnwidth}#1\end{minipage}} % Makes the box around the problem answer and puts the content inside
92
+ }
93
+
94
+ \newcommand{\homeworkSectionName}{}
95
+ \newenvironment{homeworkSection}[1]{ % New environment for sections within homework problems, takes 1 argument - the name of the section
96
+ %\renewcommand{\homeworkSectionName}{#1} % Assign \homeworkSectionName to the name of the section from the environment argument
97
+ \subsection{\homeworkSectionName} % Make a subsection with the custom name of the subsection
98
+ \enterProblemHeader{ [\homeworkSectionName]} % Header and footer within the environment
99
+ }{
100
+ \enterProblemHeader{} % Header and footer after the environment
101
+ }
102
+
103
+ %----------------------------------------------------------------------------------------
104
+ % NAME AND CLASS SECTION
105
+ %----------------------------------------------------------------------------------------
106
+
107
+ \newcommand{\hmwkTitle}{HOMEWORKTITLE} % Assignment title
108
+ \newcommand{\hmwkDueDate}{DUEDATE} % Due date
109
+ \newcommand{\hmwkClass}{COURSE} % Course/class
110
+ \newcommand{\hmwkClassTime}{} % Class/lecture time
111
+ \newcommand{\hmwkClassInstructor}{\: PROFESSOR} % Teacher/lecturer
112
+ \newcommand{\hmwkAuthorName}{AUTHOR} % Your name
113
+
114
+ %----------------------------------------------------------------------------------------
115
+ % TITLE PAGE
116
+ %----------------------------------------------------------------------------------------
117
+
118
+ \title{
119
+ \vspace{2in}
120
+ \textmd{\textbf{\hmwkClass:\ \hmwkTitle}}\\
121
+ \normalsize\vspace{0.1in}\small{Due\ on\ \hmwkDueDate}\\
122
+ \vspace{0.1in}\large{\hmwkClassInstructor}
123
+ \vspace{3in}
124
+ }
125
+ \author{\hmwkAuthorName}
126
+ \date{} % Insert date here if you want it to appear below your name
127
+
128
+ %----------------------------------------------------------------------------------------
129
+
130
+ \begin{document}
131
+
132
+ \maketitle
133
+
134
+
135
+ %----------------------------------------------------------------------------------------
136
+ % TABLE OF CONTENTS
137
+ %----------------------------------------------------------------------------------------
138
+
139
+ %\setcounter{tocdepth}{1} % Uncomment this line if you don't want subsections listed in the ToC
140
+
141
+ %\newpage
142
+ %\tableofcontents
143
+ \newpage
144
+
145
+ %----------------------------------------------------------------------------------------
146
+ % PROBLEM 9.10.1
147
+ %----------------------------------------------------------------------------------------
148
+
149
+ % To have just one problem per page, simply put a \clearpage after each problem
150
+ \begin{homeworkProblem}[Problem 1]
151
+ \end{homeworkProblem}
152
+ \clearpage
153
+ %----------------------------------------------------------------------------------------
154
+
155
+ \end{document}
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fplatex
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ platform: ruby
6
+ authors:
7
+ - Francis Phan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-02-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: highline
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.7.8
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.7.8
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: 1.7.8
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.7.8
33
+ description: Speed up work flow of writing reports
34
+ email: fphan@umass.edu
35
+ executables:
36
+ - fplatex
37
+ extensions: []
38
+ extra_rdoc_files: []
39
+ files:
40
+ - bin/fplatex
41
+ - lib/latex_hw_template.pdf
42
+ - lib/latex_hw_template.tex
43
+ homepage: https://github.com/francisphan/fplatex
44
+ licenses:
45
+ - MIT
46
+ metadata: {}
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 2.5.1
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: Latex Report template
67
+ test_files: []