Commit e6fb90b6 authored by Johannes Knoedtel's avatar Johannes Knoedtel
Browse files

initial commit

parents
workoutcard.rb
==============
This is a tool to generate LaTeX-based workout logging cards. The format in which the exercises are specified can be learned by looking at the examples lower.workout
and upper.workout.
It is not very well written but does the job well. I only released it, because other people might find it useful and I have no intent to maintain or improve the code.
Example
-------
1. Specifu your Workout
```
$ cat lower.workout
```
```ruby
{ :year => 2014,
:title => "Upper Body Workout",
:exercises => [[{ :name => "Bench Press",
:variant => "Dumbbells",
:sets => 3, :reps => 8 },
{ :name => "Seated Rows",
:variant => "Lever",
:sets => 3, :reps => 8 },
{ :name => "Fly",
:variant => "Pec Deck",
:sets => 3, :reps => 8 },
{ :name => "Cable Pulldown",
:variant => "Close Grip",
:sets => 3, :reps => 8 }],
[{ :name => "Military Press",
:variant => "Barbell",
:sets => 3, :reps => 8 },
{ :name => "Upright Row",
:variant => "Barbell",
:sets => 3, :reps => 8 },
{ :name => "Preacher Curl",
:variant => "EZ-Bar",
:sets => 3, :reps => 8 },
{ :name => "Triceps Extension",
:variant => "Dumbbell",
:sets => 3, :reps => 8 },
{ :name => "Shrug",
:variant => "Dumbbell",
:sets => 3, :reps => 8 }]] }
```
2. Build the LaTeX-Source
```
$ ./workoutcard.rb lower.workout > lower.tex
```
3. Compile it
```
$ pdflatex lower.tex
```
4. Print it
```
lpr lower.pdf
```
Dependencies
------------
- Ruby 2.1
- LaTeX, including packages:
- textcomp
- geometry
- array
- realboxes
- xfrac
{ :year => 2014,
:title => "Upper Body Workout",
:exercises => [[{ :name => "Bench Press",
:variant => "Dumbbells",
:sets => 3, :reps => 8 },
{ :name => "Seated Rows",
:variant => "Lever",
:sets => 3, :reps => 8 },
{ :name => "Fly",
:variant => "Pec Deck",
:sets => 3, :reps => 8 },
{ :name => "Cable Pulldown",
:variant => "Close Grip",
:sets => 3, :reps => 8 }],
[{ :name => "Military Press",
:variant => "Barbell",
:sets => 3, :reps => 8 },
{ :name => "Upright Row",
:variant => "Barbell",
:sets => 3, :reps => 8 },
{ :name => "Preacher Curl",
:variant => "EZ-Bar",
:sets => 3, :reps => 8 },
{ :name => "Triceps Extension",
:variant => "Dumbbell",
:sets => 3, :reps => 8 },
{ :name => "Shrug",
:variant => "Dumbbell",
:sets => 3, :reps => 8 }]] }
{ :year => 2014,
:title => "Lower Body Workout",
:exercises => [[{ :name => "Squat",
:variant => "Barbell",
:sets => 5, :reps => 5 },
{ :name => "Deadlift",
:variant => "Barbell",
:sets => 5, :reps => 5 }],
[{ :name => "Calv Extension",
:variant => "Seated",
:sets => 3, :reps => 12 },
{ :name => "Hip Abduction",
:variant => "Seated",
:sets => 3, :reps => 12 },
{ :name => "Hip Flexion",
:variant => "Seated",
:sets => 3, :reps => 12 }],
[{ :name => "Situp",
:variant => "Incline",
:sets => 3, :reps => 10 },
{ :name => "Kneeraise",
:variant => "Captains Chair",
:sets => 3, :reps => 8 },
{ :name => "Twisting Situp",
:variant => "",
:sets => 3, :reps => 16 }]] }
#!/bin/env ruby
def cardify(title, year, exercise_groups)
pre = <<HERE % [title]
\\vspace*{.2cm}
\\framebox{
\\begin{minipage}[t][.4\\paperheight][t]{.45\\paperwidth}
\\centering
\\vspace*{.4cm}
\\large\\textsc{%s}
\\footnotesize\\\\[.4cm]
\\begin{tabular}[h]{p{1ex}p{2.7cm}|clcl|c}
&\\multicolumn{0}{c|}{\\textsc{Exercise}}&\\multicolumn{4}{c|}{\\textsc{Weight}}&\\textsc{Difficulty}\\\\
&&\\multicolumn{2}{c}{\\textit{intended}}&\\multicolumn{2}{c|}{\\textit{actual}}&\\\\
\\hline
HERE
middle = (exercise_groups.map { |group| (group.map { |ex|
exercise(ex[:name], ex[:variant], ex[:sets], ex[:reps]) }).join (next_line) }).join next_line(true)
post = <<HERE % [year]
\\end{tabular}
\\vfill
\\normalsize
\\textnumero $\\,\\dots$\\qquad Date: $%s/\\dots/\\dots$
\\vspace*{.5cm}
\\end{minipage}}
HERE
pre + middle + post
end
def exercise(name, variant, sets, reps)
'$\sfrac{%s}{%s}$&{\textbf{%s}\par\hspace*{7pt}\textit{%s}}&\fillindots&\kg&\fillindots&\kg&\fillindots' % [sets, reps, name, variant]
end
def next_line(hline = false)
'\\\\' + (hline ? '\hline' : '') + ?\n
end
def generate_doc(title, year, exercise_groups)
preamble = <<HERE
\\documentclass[a4paper]{article}
\\usepackage{textcomp}
\\usepackage[margin=.3cm]{geometry}
\\usepackage{array}
\\usepackage{realboxes}
\\usepackage{xfrac}
\\begin{document}
\\setlength\\extrarowheight{3pt}
\\setlength{\\parindent}{0cm}
\\newcommand{\\fillindots}{\\raisebox{-.3cm}{$\\dots\\dots$}}
\\newcommand{\\kg}{\\raisebox{-.2cm}{kg}}
HERE
middle = cardify(title, year, exercise_groups)
postamble = '\end{document}'
preamble + middle * 2 + '\\\\\vspace*{1cm}' + middle * 2 + postamble
end
workout = eval File.open(ARGV[0]).read
puts (generate_doc workout[:title], workout[:year], workout[:exercises])
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment