Skip to content

Instantly share code, notes, and snippets.

@J0J0
Last active November 18, 2016 18:42
Show Gist options
  • Save J0J0/227460231c076eeac9e74b993a6dd98c to your computer and use it in GitHub Desktop.
Save J0J0/227460231c076eeac9e74b993a6dd98c to your computer and use it in GitHub Desktop.
scoretable.sty
==============
Put the package file in a place where LaTeX can find it; e.g.:
* place it in your TEXMFHOME (the command
kpsewhich -var-value TEXMFHOME
should tell you where this is) under tex/latex/;
on many Linux distributions
~/texmf/tex/latex/
should be the correct path.
* place it directly in the same path of the .tex file that is
supposed to load the package.
Load the package with
\usepackage{scoretable}
and use the following commands:
\addscoretableentry{X}
adds a column labeled "X" to the table
\addscoretableentrycrossed{X}
like the one before but "crosses" out the field for the points
\makescoretable
print the score table
Optional arguments to the package are:
color color of the table (default: gray)
vlines "false" disables the vertical lines of the table (default: true)
appendsum "false" disables the \sum column at the end (default: true)
filename specifies the cache file (default: scoretable.tmp)
Note that you have to compile twice for the table to be shown correctly
(like with \tableofcontents).
See also the example and example2 .tex and .pdf files for some use cases.
\documentclass[11pt,a4paper,ngerman]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{scoretable}
\newcommand{\task}[1]{\section*{Aufgabe #1}\addscoretableentry{#1}}
\newcommand{\ctask}[2]{\section*{#1}\addscoretableentry{#2}}
\newcommand{\notask}{\addscoretableentrycrossed}
\pagestyle{empty}
\begin{document}
\begin{center}
\LARGE Aussagekräftiger Titel oder was auch immer~\dots
\end{center}
\begin{center}
\makescoretable
\bigskip
\end{center}
\task{1}
foo bar
\notask{2}
\task{3}
blubber
\notask{4}
\ctask{Bonusaufgabe}{B}
lorem ipsum
\end{document}
\documentclass[10pt,a4paper,ngerman]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}
%%%%%
\usepackage[%
color=blue, % change the table color from gray to blue,
filename=\jobname.scoretable, % use the source's filename
% for the temporary output file,
vlines=false, % disable the vertical lines of the table,
appendsum=false % disable the "sum column" at the end.
]{scoretable}
% always create entries for tasks numbered 1--4
\addscoretableentry{1}\addscoretableentry{2}
\addscoretableentry{3}\addscoretableentry{4}
%%%%%
\pagestyle{empty}
\setlength{\unitlength}{1cm}
\begin{document}
\begin{picture}(0,0)(-8,-2)
\put(0,0){\makescoretable}
\end{picture}
%
\begin{center}
\LARGE Aussagekräftiger Titel oder was auch immer~\dots
\end{center}
\section*{abc}
foo bar
\section*{def}
blubber
\end{document}
%%% (ISC License) %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Copyright (c) 2013, 2016, Johannes Prem %%
%% %%
%% Permission to use, copy, modify, and/or distribute this software for %%
%% any purpose with or without fee is hereby granted, provided that the %%
%% above copyright notice and this permission notice appear in all copies. %%
%% %%
%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL %%
%% WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED %%
%% WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE %%
%% AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL %%
%% DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR %%
%% PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER %%
%% TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR %%
%% PERFORMANCE OF THIS SOFTWARE. %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{scoretable}
\RequirePackage{catchfile}
\RequirePackage{xcolor}
\RequirePackage{graphicx}
\RequirePackage{kvoptions}
\SetupKeyvalOptions{family=ST,prefix=@scoretab@opt@}
\DeclareStringOption[gray]{color}
\DeclareStringOption[scoretable.tmp]{filename}
\DeclareBoolOption[true]{vlines}
\DeclareBoolOption[true]{appendsum}
\ProcessKeyvalOptions*
% execute #1 for each token in #2
\providecommand\@callforeachtoken[2]{%
\@tfor \next := #2 \do{%
\expandafter#1\expandafter{\next}%
}%
}
\IfFileExists{\@scoretab@opt@filename}{
\CatchFileDef{\@scoretab@tokens}{\@scoretab@opt@filename}{}
}{
\let\@scoretab@tokens=\@empty%
}
\newwrite\@scoretab@out
\immediate\openout\@scoretab@out=\@scoretab@opt@filename
\AtEndDocument{\immediate\closeout\@scoretab@out}
\newsavebox\@scoretab@scoretablebox
\newcommand{\@scoretab@addentry}[1]{\immediate\write\@scoretab@out{{#1}}}
\newcommand{\@scoretab@addcrossedentry}[1]{\@scoretab@addentry{%
\unexpanded{\makebox[0pt]{\raisebox{\dimexpr-0.5\baselineskip-0.4cm-3.5pt}{\rotatebox{21.8}{\rule{1.077cm}{0.5pt}}}}\makebox[0pt]}{#1}}}
\newcommand{\@scoretab@compose@entry}[1]{\makebox[1.5cm]{#1}}
\newcommand{\@scoretab@compose@inter}{\makebox[0pt]{\raisebox{-1.75\baselineskip}{\rule{1pt}{2.5\baselineskip}}}}
\if@scoretab@opt@vlines
\newcommand{\@scoretab@compose@iterationcmd}[1]{\@scoretab@compose@entry{#1}\@scoretab@compose@inter}
\else
\newcommand{\@scoretab@compose@iterationcmd}[1]{\@scoretab@compose@entry{#1}}
\fi
\newcommand{\@scoretab@gentable}{%
\sbox\@scoretab@scoretablebox{%
\large\color{\@scoretab@opt@color}%
\expandafter\@callforeachtoken\expandafter\@scoretab@compose@iterationcmd\expandafter{\@scoretab@tokens}%
\if@scoretab@opt@appendsum%
\@scoretab@compose@entry{$\mathsurround=0pt\sum$}%
\fi%
}%
\usebox{\@scoretab@scoretablebox}%
\llap{\raisebox{-0.5\baselineskip}{\color{\@scoretab@opt@color}\rule{\wd\@scoretab@scoretablebox}{1pt}}}%
\\%
}
% user space commands
\let\addscoretableentry=\@scoretab@addentry
\let\addscoretableentrycrossed=\@scoretab@addcrossedentry
\let\makescoretable=\@scoretab@gentable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment