| author | wenzelm | 
| Fri, 28 Apr 2017 11:29:41 +0200 | |
| changeset 65600 | 138ffa41dc54 | 
| parent 56786 | 13ede133f6eb | 
| child 66948 | 47249c5ec3a4 | 
| permissions | -rwxr-xr-x | 
| 48682 | 1 | #!/usr/bin/env bash | 
| 2 | # | |
| 3 | # Author: Makarius | |
| 4 | # | |
| 5 | # DESCRIPTION: prepare session root directory | |
| 6 | ||
| 7 | ||
| 8 | ## diagnostics | |
| 9 | ||
| 10 | PRG="$(basename "$0")" | |
| 11 | ||
| 12 | function usage() | |
| 13 | {
 | |
| 14 | echo | |
| 48739 | 15 | echo "Usage: isabelle $PRG [OPTIONS] [DIR]" | 
| 48682 | 16 | echo | 
| 48739 | 17 | echo " Options are:" | 
| 18 | echo " -d enable document preparation" | |
| 19 | echo " -n NAME alternative session name (default: DIR base name)" | |
| 20 | echo | |
| 21 | echo " Prepare session root DIR (default: current directory)." | |
| 48682 | 22 | echo | 
| 23 | exit 1 | |
| 24 | } | |
| 25 | ||
| 26 | function fail() | |
| 27 | {
 | |
| 28 | echo "$1" >&2 | |
| 29 | exit 2 | |
| 30 | } | |
| 31 | ||
| 32 | ||
| 33 | ## process command line | |
| 34 | ||
| 48739 | 35 | # options | 
| 36 | ||
| 37 | DOC="" | |
| 38 | NAME="" | |
| 48682 | 39 | |
| 48739 | 40 | while getopts "n:d" OPT | 
| 41 | do | |
| 42 | case "$OPT" in | |
| 43 | d) | |
| 44 | DOC="true" | |
| 45 | ;; | |
| 46 | n) | |
| 47 | NAME="$OPTARG" | |
| 48 | ;; | |
| 49 | \?) | |
| 50 | usage | |
| 51 | ;; | |
| 52 | esac | |
| 53 | done | |
| 48682 | 54 | |
| 48739 | 55 | shift $(($OPTIND - 1)) | 
| 56 | ||
| 57 | ||
| 58 | # args | |
| 59 | ||
| 60 | if [ "$#" -eq 0 ]; then | |
| 61 | DIR="." | |
| 62 | elif [ "$#" -eq 1 ]; then | |
| 63 | DIR="$1" | |
| 64 | shift | |
| 65 | else | |
| 66 | usage | |
| 67 | fi | |
| 48682 | 68 | |
| 69 | ||
| 70 | ## main | |
| 71 | ||
| 48739 | 72 | mkdir -p "$DIR" || fail "Bad directory: \"$DIR\"" | 
| 73 | ||
| 74 | [ -z "$NAME" ] && NAME="$(basename "$(cd "$DIR"; pwd -P)")" | |
| 75 | ||
| 76 | [ -e "$DIR/ROOT" ] && fail "Cannot overwrite existing $DIR/ROOT" | |
| 77 | ||
| 78 | [ "$DOC" = true -a -e "$DIR/document" ] && \ | |
| 79 | fail "Cannot overwrite existing $DIR/document" | |
| 48682 | 80 | |
| 81 | echo | |
| 48739 | 82 | echo "Preparing session \"$NAME\" in \"$DIR\"" | 
| 48682 | 83 | |
| 84 | ||
| 48739 | 85 | # ROOT | 
| 48682 | 86 | |
| 48739 | 87 | echo " creating $DIR/ROOT" | 
| 48682 | 88 | |
| 48739 | 89 | if [ "$DOC" = true ]; then | 
| 90 | cat > "$DIR/ROOT" <<EOF | |
| 91 | session "$NAME" = "$ISABELLE_LOGIC" + | |
| 52743 | 92 | options [document = pdf, document_output = "output"] | 
| 48739 | 93 | theories [document = false] | 
| 56786 | 94 | (* Foo *) | 
| 95 | (* Bar *) | |
| 48739 | 96 | theories | 
| 97 | (* Baz *) | |
| 56786 | 98 | document_files | 
| 99 | "root.tex" | |
| 48682 | 100 | EOF | 
| 48739 | 101 | else | 
| 102 | cat > "$DIR/ROOT" <<EOF | |
| 103 | session "$NAME" = "$ISABELLE_LOGIC" + | |
| 104 | options [document = false] | |
| 105 | theories | |
| 56786 | 106 | (* Foo *) | 
| 107 | (* Bar *) | |
| 108 | (* Baz *) | |
| 48739 | 109 | EOF | 
| 110 | fi | |
| 48682 | 111 | |
| 112 | ||
| 113 | # document directory | |
| 114 | ||
| 48739 | 115 | if [ "$DOC" = true ]; then | 
| 116 | echo " creating $DIR/document/root.tex" | |
| 48682 | 117 | |
| 48739 | 118 | mkdir "$DIR/document" || fail "Bad directory: \"$DIR/document\"" | 
| 119 | ||
| 120 | TITLE=$(echo "$NAME" | tr _ - | tr -d '\\') | |
| 121 | AUTHOR=$(echo "By $USER" | tr _ - | tr -d '\\') | |
| 122 | ||
| 123 | cat > "$DIR/document/root.tex" <<EOF | |
| 48682 | 124 | \documentclass[11pt,a4paper]{article}
 | 
| 125 | \usepackage{isabelle,isabellesym}
 | |
| 126 | ||
| 127 | % further packages required for unusual symbols (see also | |
| 128 | % isabellesym.sty), use only when needed | |
| 129 | ||
| 130 | %\usepackage{amssymb}
 | |
| 131 | %for \<leadsto>, \<box>, \<diamond>, \<sqsupset>, \<mho>, \<Join>, | |
| 132 | %\<lhd>, \<lesssim>, \<greatersim>, \<lessapprox>, \<greaterapprox>, | |
| 133 | %\<triangleq>, \<yen>, \<lozenge> | |
| 134 | ||
| 135 | %\usepackage{eurosym}
 | |
| 136 | %for \<euro> | |
| 137 | ||
| 138 | %\usepackage[only,bigsqcap]{stmaryrd}
 | |
| 139 | %for \<Sqinter> | |
| 140 | ||
| 141 | %\usepackage{eufrak}
 | |
| 142 | %for \<AA> ... \<ZZ>, \<aa> ... \<zz> (also included in amssymb) | |
| 143 | ||
| 144 | %\usepackage{textcomp}
 | |
| 145 | %for \<onequarter>, \<onehalf>, \<threequarters>, \<degree>, \<cent>, | |
| 146 | %\<currency> | |
| 147 | ||
| 148 | % this should be the last package used | |
| 149 | \usepackage{pdfsetup}
 | |
| 150 | ||
| 151 | % urls in roman style, theory text in math-similar italics | |
| 152 | \urlstyle{rm}
 | |
| 153 | \isabellestyle{it}
 | |
| 154 | ||
| 155 | % for uniform font size | |
| 156 | %\renewcommand{\isastyle}{\isastyleminor}
 | |
| 157 | ||
| 158 | ||
| 159 | \begin{document}
 | |
| 160 | ||
| 161 | \title{$TITLE}
 | |
| 162 | \author{$AUTHOR}
 | |
| 163 | \maketitle | |
| 164 | ||
| 165 | \tableofcontents | |
| 166 | ||
| 167 | % sane default for proof documents | |
| 168 | \parindent 0pt\parskip 0.5ex | |
| 169 | ||
| 170 | % generated text of all theories | |
| 171 | \input{session}
 | |
| 172 | ||
| 173 | % optional bibliography | |
| 174 | %\bibliographystyle{abbrv}
 | |
| 175 | %\bibliography{root}
 | |
| 176 | ||
| 177 | \end{document}
 | |
| 178 | ||
| 179 | %%% Local Variables: | |
| 180 | %%% mode: latex | |
| 181 | %%% TeX-master: t | |
| 182 | %%% End: | |
| 183 | EOF | |
| 184 | fi | |
| 185 | ||
| 186 | # notes | |
| 187 | ||
| 48739 | 188 | declare -a DIR_PARTS=($DIR) | 
| 189 | if [ ${#DIR_PARTS[@]} = 1 ]; then
 | |
| 190 | OPT_DIR="-D $DIR" | |
| 48683 | 191 | else | 
| 48739 | 192 | OPT_DIR="-D \"$DIR\"" | 
| 48683 | 193 | fi | 
| 194 | ||
| 48682 | 195 | cat <<EOF | 
| 196 | ||
| 48739 | 197 | Now use the following command line to build the session: | 
| 48682 | 198 | |
| 48805 
c3ea910b3581
explicit document_output directory, without implicit purge of default in ISABELLE_BROWSER_INFO;
 wenzelm parents: 
48739diff
changeset | 199 | isabelle build $OPT_DIR | 
| 48682 | 200 | |
| 201 | EOF | |
| 202 |