| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | # |
| 3 | # lpsmag CONFIGFILE |
| 4 | # |
| 5 | # creates a LaTeX file for the production |
| 6 | # a Sudoku magazine with lpsudoku.sty |
| 7 | # |
| 8 | # License: LPPL |
| 9 | # |
| 10 | VERSION="v1.1 (06/05/2013)" |
| 11 | CONFIGFILE="$1" |
| 12 | TEXFILE="lpsmag.tex" |
| 13 | TEXFILEBAK="${TEXFILE}.bak" |
| 14 | typeset -i COUNT=0 |
| 15 | SUDOKUPP="6" |
| 16 | SUDOKUPPD="12" |
| 17 | # |
| 18 | if [scip-shell system . . `[`. -z "$CONFIGFILE" ] |
| 19 | then |
| 20 | echoscip-shell system . . echo. "no config file" |
| 21 | echoscip-shell system . . echo. "Usage: `basenamescip-shell system . . basename. $0` configfile" |
| 22 | exit 1 |
| 23 | fi |
| 24 | # |
| 25 | exec 1> $TEXFILE |
| 26 | # |
| 27 | startpuzzlesscip-shell shell texlive-extra 2026.20260527-1 startpuzzles().() |
| 28 | { |
| 29 | echoscip-shell system . . echo. "\lpsudokusetup{scale=0.75,width=6.8cm,fontsize=Large,cvoffset=-24pt}" |
| 30 | echoscip-shell system . . echo. "\setpuzzlecounter{1}" |
| 31 | } |
| 32 | # |
| 33 | startsolutionsscip-shell shell texlive-extra 2026.20260527-1 startsolutions().() |
| 34 | { |
| 35 | echoscip-shell system . . echo. "\lpsudokusetup{scale=0.5,width=4.6cm,fontsize=normalsize}" |
| 36 | echoscip-shell system . . echo. "\setpuzzlecounter{1}" |
| 37 | } |
| 38 | # |
| 39 | pagescip-shell shell texlive-extra 2026.20260527-1 page().() |
| 40 | { |
| 41 | local name="$1" |
| 42 | local difficulty="$2" |
| 43 | qqwing --generate $SUDOKUPP --one-line --difficulty $difficulty >${name}.81 |
| 44 | catscip-shell system . . cat. ${name}.81 | qqwing --solve --one-line >${name}_sol.81 |
| 45 | } |
| 46 | # |
| 47 | typesetpagescip-shell shell texlive-extra 2026.20260527-1 typesetpage().() |
| 48 | { |
| 49 | local name="$1" |
| 50 | local last="$2" |
| 51 | local puzzlenummer="uneven" |
| 52 | COUNT=0 |
| 53 | echoscip-shell system . . echo. "%startpage" |
| 54 | for puzzle in `catscip-shell system . . cat. ${name}.81` |
| 55 | do |
| 56 | ((COUNT++)) |
| 57 | echoscip-shell system . . echo. $puzzle >puzzle.81 |
| 58 | createlpsudoku -i puzzle.81 |
| 59 | if [scip-shell system . . `[`. "$puzzlenummer" = "uneven" ] |
| 60 | then |
| 61 | echoscip-shell system . . echo. "\hfill" |
| 62 | # toggle even/uneven |
| 63 | puzzlenummer="even" |
| 64 | else |
| 65 | # no \vfill after last lpsudoku |
| 66 | # environment of the page |
| 67 | if [scip-shell system . . `[`. $COUNT -lt $SUDOKUPP ] |
| 68 | then |
| 69 | echoscip-shell system . . echo. "\vfill" |
| 70 | else |
| 71 | if [scip-shell system . . `[`. "$last" != "last" ] |
| 72 | then |
| 73 | echoscip-shell system . . echo. "\clearpage" |
| 74 | fi |
| 75 | fi |
| 76 | puzzlenummer="uneven" |
| 77 | fi |
| 78 | done |
| 79 | } |
| 80 | # |
| 81 | tspforscip-shell shell texlive-extra 2026.20260527-1 tspfor().() |
| 82 | { |
| 83 | local name="$1" |
| 84 | local last="$2" |
| 85 | local puzzlepos="one" |
| 86 | for puzzle in `catscip-shell system . . cat. ${name}.81` |
| 87 | do |
| 88 | ((COUNT++)) |
| 89 | if [scip-shell system . . `[`. $COUNT -eq 1 -o $COUNT -eq 7 ] |
| 90 | then |
| 91 | echoscip-shell system . . echo. "%startpage" |
| 92 | fi |
| 93 | echoscip-shell system . . echo. $puzzle >puzzle.81 |
| 94 | createlpsudoku -i puzzle.81 |
| 95 | if [scip-shell system . . `[`. "$puzzlepos" = "one" ] |
| 96 | then |
| 97 | echoscip-shell system . . echo. "\hfill" |
| 98 | puzzlepos="two" |
| 99 | elif [scip-shell system . . `[`. "$puzzlepos" = "two" ] |
| 100 | then |
| 101 | echoscip-shell system . . echo. "\hfill" |
| 102 | puzzlepos="three" |
| 103 | else |
| 104 | if [scip-shell system . . `[`. $COUNT -lt $SUDOKUPPD ] |
| 105 | then |
| 106 | echoscip-shell system . . echo. "\vfill" |
| 107 | puzzlepos="one" |
| 108 | else |
| 109 | if [scip-shell system . . `[`. "$last" = "last" ] |
| 110 | then |
| 111 | puzzlepos="one" |
| 112 | else |
| 113 | echoscip-shell system . . echo. "\clearpage" |
| 114 | puzzlepos="one" |
| 115 | fi |
| 116 | fi |
| 117 | fi |
| 118 | done |
| 119 | } |
| 120 | # |
| 121 | typesetsolpagescip-shell shell texlive-extra 2026.20260527-1 typesetsolpage().() |
| 122 | { |
| 123 | local name1="$1_sol" |
| 124 | local name2="$2_sol" |
| 125 | local last="$3" |
| 126 | COUNT=0 |
| 127 | tspforscip-shell shell texlive-extra 2026.20260527-1 tspfor(). $name1 $last |
| 128 | tspforscip-shell shell texlive-extra 2026.20260527-1 tspfor(). $name2 $last |
| 129 | } |
| 130 | # |
| 131 | addcounterstylescip-shell shell texlive-extra 2026.20260527-1 addcounterstyle().() |
| 132 | { |
| 133 | grepscip-shell system . . grep. -ne'startpage' $TEXFILE | cutscip-shell system . . cut. -d':' -f1 >csl.tmp |
| 134 | for linenumber in `catscip-shell system . . cat. csl.tmp` |
| 135 | do |
| 136 | COUNT="$linenumber" |
| 137 | ((COUNT++)) |
| 138 | echoscip-shell system . . echo. "$COUNT a [counterstyle=left]" >>sed.tmp |
| 139 | echoscip-shell system . . echo. "$linenumber d" >>sed.tmp |
| 140 | done |
| 141 | sedscip-shell system . . sed. -f sed.tmp $TEXFILE >$TEXFILEBAK |
| 142 | rmscip-shell system . . rm. $TEXFILE |
| 143 | mvscip-shell system . . mv. $TEXFILEBAK $TEXFILE |
| 144 | } |
| 145 | # |
| 146 | addpercentscip-shell shell texlive-extra 2026.20260527-1 addpercent().() |
| 147 | { |
| 148 | sedscip-shell system . . sed. -e's/$/%/' $TEXFILE >$TEXFILEBAK |
| 149 | rmscip-shell system . . rm. $TEXFILE |
| 150 | mvscip-shell system . . mv. $TEXFILEBAK $TEXFILE |
| 151 | } |
| 152 | # |
| 153 | deleteauxfilesscip-shell shell texlive-extra 2026.20260527-1 deleteauxfiles().() |
| 154 | { |
| 155 | rmscip-shell system . . rm. *.81 |
| 156 | rmscip-shell system . . rm. *.tmp |
| 157 | } |
| 158 | # |
| 159 | catscip-shell system . . cat. >preamble.tmp <<EOF |
| 160 | \documentclass[a4paper]{article}% |
| 161 | \usepackage[bottom=3cm,top=3cm,left=2.7cm,right=2.7cm]{geometry} |
| 162 | \usepackage{logicpuzzle}% |
| 163 | \lpsudokusetup{width=5cm,scale=0.55,fontsize=normalsize}% |
| 164 | EOF |
| 165 | # |
| 166 | catscip-shell system . . cat. preamble.tmp |
| 167 | echoscip-shell system . . echo. "\begin{document}" |
| 168 | # |
| 169 | . $CONFIGFILE |
| 170 | # |
| 171 | echoscip-shell system . . echo. "\end{document}" |
| 172 | # |
| 173 | addcounterstylescip-shell shell texlive-extra 2026.20260527-1 addcounterstyle(). |
| 174 | addpercentscip-shell shell texlive-extra 2026.20260527-1 addpercent(). |
| 175 | deleteauxfilesscip-shell shell texlive-extra 2026.20260527-1 deleteauxfiles(). |
| 176 | exit 0 |
| 177 | # |