| 1 | |
| 2 | Support scripts |
| 3 | =============== |
| 4 | |
| 5 | <!-- TOC depthfrom:2 --> |
| 6 | |
| 7 | - [make-spreads.sh](#make-spreadssh) |
| 8 | - [Theory of operation](#theory-of-operation) |
| 9 | - [Automatic template inferencing](#automatic-template-inferencing) |
| 10 | - [Manual template selection](#manual-template-selection) |
| 11 | - [Template tweaking](#template-tweaking) |
| 12 | - [Manual spread layouts](#manual-spread-layouts) |
| 13 | - [Templates](#templates) |
| 14 | - [Image captions](#image-captions) |
| 15 | - [Environment variables and configuration](#environment-variables-and-configuration) |
| 16 | - [cls2tex.sh](#cls2texsh) |
| 17 | |
| 18 | <!-- /TOC --> |
| 19 | |
| 20 | |
| 21 | --- |
| 22 | |
| 23 | `make-spreads.sh` |
| 24 | ---------------- |
| 25 | |
| 26 | Generate LaTeX block of pages/spreads from a directory tree. |
| 27 | |
| 28 | This was initially intended as a means to convert the exported directory |
| 29 | tree from an image viewer where image/text sequencing was done, but it |
| 30 | can also be used standalone. |
| 31 | |
| 32 | Goals: |
| 33 | - Decouple layout, sequencing, images, processing and different texts |
| 34 | to enable different people to work on them independently and in |
| 35 | parallel, |
| 36 | - Simplify editing the page/spread sequence, |
| 37 | - Automate the build process. |
| 38 | |
| 39 | |
| 40 | A typical project tree: |
| 41 | ``` |
| 42 | book/ |
| 43 | ├── templates/ . . . . . . . . . . . . Global templates. |
| 44 | │ ├── imagepage.tex . . . . . . . . . Single page image template, |
| 45 | │ ├── textpage.tex . . . . . . . . . Single page text template, |
| 46 | │ │ These are used to build spreads |
| 47 | │ │ when no explicit template matches. |
| 48 | │ ├── blank-image.tex |
| 49 | │ ├── image-blank.tex |
| 50 | │ ├── image-image.tex |
| 51 | │ ├── fullbleed.tex |
| 52 | │ └── ... |
| 53 | ├── spreads/ . . . . . . . . . . . . . Main block layout. |
| 54 | │ ├── 00/ . . . . . . . . . . . . . . A basic spread. |
| 55 | │ │ ├── tweaks.tex The spread template is built |
| 56 | │ │ └── 0-DSC02432.jpg automatically with tweaks.tex |
| 57 | │ │ prepended. |
| 58 | │ ├── 01/ |
| 59 | │ │ ├── 0-DSC02439.jpg |
| 60 | │ │ └── 1-intro.txt |
| 61 | │ ├── 02/ |
| 62 | │ │ ├── fullbleed.tpl . . . . . . . Explicitly use a global template. |
| 63 | │ │ └── 1-DSC02511.jpg |
| 64 | │ ├── 03/ |
| 65 | │ │ ├── 0-DSC02509-0.jpg |
| 66 | │ │ └── 1-DSC02506-0.jpg |
| 67 | │ └── ... |
| 68 | ├── captions/ . . . . . . . . . . . . . Image captions. |
| 69 | │ ├── DSC02432.txt |
| 70 | │ ├── DSC02439.txt |
| 71 | │ ├── DSC02511.txt |
| 72 | │ └── ... |
| 73 | ├── setup.tex . . . . . . . . . . . . . Book block setup. |
| 74 | │ This is included by all top level |
| 75 | │ .tex files like block.tex, |
| 76 | │ cover.tex, ...etc. |
| 77 | ├── block.tex . . . . . . . . . . . . . Block skeletal layout. |
| 78 | │ This usually includes the titles, |
| 79 | │ technical pages and sources the |
| 80 | │ ./block-spreads.tex. |
| 81 | ├── block-spreads.tex . . . . . . . . . The generated block content. |
| 82 | ├── cover.tex . . . . . . . . . . . . . Cover layout. |
| 83 | ├── jacket.tex . . . . . . . . . . . . Dust jacket layout. |
| 84 | └── ... |
| 85 | ``` |
| 86 | |
| 87 | For a full example see: ../examples/book |
| 88 | |
| 89 | Generate the block: |
| 90 | ```shell |
| 91 | $ make-spreads.sh ./spreads > block-spreads.tex |
| 92 | ``` |
| 93 | |
| 94 | Note that `make-spreads.sh` does not force a specific layout outside of |
| 95 | the `spreads` directory, all paths are configurable. The way the root |
| 96 | files are structured in this example is just one way to organize a |
| 97 | book's source code with minimal code duplication. |
| 98 | |
| 99 | |
| 100 | For runtime help see: |
| 101 | ```shell |
| 102 | $ make-spreads.sh --help |
| 103 | ``` |
| 104 | |
| 105 | |
| 106 | ### Theory of operation |
| 107 | |
| 108 | <!-- XXX spreads vs. pages --> |
| 109 | |
| 110 | The system is designed to minimize the effort in laying out pages, so |
| 111 | when designing a book the focus should be on global templates and on |
| 112 | helping `make-spreads.sh` build them rather than trying to layout each |
| 113 | spread individually. |
| 114 | |
| 115 | There are several ways to arrive at a book layout starting from the |
| 116 | concept, through the edit, sequencing, structuring and the graphic |
| 117 | design, we here will focus on the stage of the process where a body of |
| 118 | work is starting to look like a book. |
| 119 | |
| 120 | When starting work on a layout it is good to at least have a basic |
| 121 | understanding of the book's: |
| 122 | - structure and how it may change, |
| 123 | - general look (i.e. core templates), |
| 124 | - exceptions from the above. |
| 125 | |
| 126 | In most cases all of the above will change in one way or another during |
| 127 | the project's lifespan, and the main goal of this stage is to make this |
| 128 | change as efgortless as possible -- it's all about providing the freedom |
| 129 | to make changes instead of growing the work invested and thus making |
| 130 | change more and more expensive. |
| 131 | |
| 132 | The first question is what is the _structure_ of the book we are making? |
| 133 | Will it have chapters? How many? Text? how much, how should it be |
| 134 | placed? How are we going to deal with the title? How are we going |
| 135 | to present the images, full bleed, no bleeds, small, big, one per page |
| 136 | or multiples, ...etc.? At this stage this is about the presentation, |
| 137 | the flow of the work and not about the actual design. How many typical |
| 138 | spreads (i.e. spread templates) should it have? A good number should be |
| 139 | small-ish, for example 3-4 spread templates is a good number, if you |
| 140 | count 10+ then you might be overcomplicating things, but note, there are |
| 141 | no rules, a book where each spread is individually and manually layed out |
| 142 | may work as well as a book with just a single template spread, but in |
| 143 | general for a photo book the focus is on the project and the layout |
| 144 | should work with it without overwhelming it. |
| 145 | |
| 146 | Have answers, good, now it's time to build those mock layouts and make |
| 147 | them into basic templates. |
| 148 | |
| 149 | It would be simplest to start work with the basic templates provided by |
| 150 | `photobook` (see: ../examples/spread templates/templates/) and rework |
| 151 | them when or if needed. |
| 152 | |
| 153 | The templates are split into two levels: |
| 154 | - Page templates |
| 155 | These are typical pages that makeup a spread, usually an |
| 156 | image page (`imagepage.tex`), a text page (`textpage.tex`), and an |
| 157 | optional empty page (`emptypage.tex`), `make-spreads.sh` can combine |
| 158 | them to build spreads automatically. |
| 159 | - Spread templates |
| 160 | These typeset a spread and can be either automatically inferred from |
| 161 | the structure or manually selected. |
| 162 | |
| 163 | |
| 164 | #### Automatic template inferencing |
| 165 | |
| 166 | If no explicit template is defined (see next section) `make-spreads.sh` |
| 167 | will try and infer a template based on the number of images in the |
| 168 | spread directory, if that is not possible the it will build a spread |
| 169 | from page templates based on the sequence of first two image/text files. |
| 170 | |
| 171 | For example with the default settings and the templates defined above: |
| 172 | |
| 173 | ``` |
| 174 | ├── 01/ |
| 175 | │ ├── 0-DSC02439.jpg |
| 176 | │ └── 1-intro.txt |
| 177 | ``` |
| 178 | |
| 179 | Will use `imagepage.tex` and `textpage.tex` templates to build the spread, |
| 180 | while the following: |
| 181 | |
| 182 | ``` |
| 183 | ├── 03/ |
| 184 | │ ├── 0-DSC02509-0.jpg |
| 185 | │ └── 1-DSC02506-0.jpg |
| 186 | ``` |
| 187 | |
| 188 | Will use `image-image.tex`. |
| 189 | |
| 190 | Note that if a spread template is not found `make-spreads.sh` fallback to |
| 191 | page templates, e.g. if we delete `image-image.tex` then `imagepage.tex` |
| 192 | will be used for both pages of the spread instead. |
| 193 | |
| 194 | If only one image/text file is provided then `make-spreads.sh` will set it |
| 195 | on the right page of the spread using the appropriate page template and |
| 196 | leave the left page blank. |
| 197 | |
| 198 | A black page uses `blankpage.tex` template if available, otherwise a |
| 199 | trivial blank page is used: |
| 200 | ```latex |
| 201 | \null |
| 202 | \newpage |
| 203 | ``` |
| 204 | |
| 205 | <!-- XXX |
| 206 | Template search order: |
| 207 | - spread directory |
| 208 | - template directory |
| 209 | --> |
| 210 | |
| 211 | |
| 212 | #### Manual template selection |
| 213 | |
| 214 | A template can be selected manually by providing a file in the form: |
| 215 | |
| 216 | ```bnf |
| 217 | <template-name>.tpl |
| 218 | ``` |
| 219 | |
| 220 | The content of this file is ignored and `templates/<template-name>.tex` |
| 221 | will be used for that spread. |
| 222 | |
| 223 | Example: |
| 224 | ``` |
| 225 | ├── 02/ |
| 226 | │ ├── fullbleed.tpl |
| 227 | │ └── 1-DSC02511.jpg |
| 228 | ``` |
| 229 | |
| 230 | Here `templates/fullbleed.tex` will be used. |
| 231 | |
| 232 | |
| 233 | #### Template tweaking |
| 234 | |
| 235 | If the file `tweaks.tex` is present in the spread directory its contents |
| 236 | are included in the built block at the start of that spread. |
| 237 | |
| 238 | This can be useful to _tweak_ the spread, for example to set page/font |
| 239 | color, tweak image positioning in some of the `photobook`'s template |
| 240 | spread macros (see: tweaking section in photobook.pdf). |
| 241 | |
| 242 | Example: |
| 243 | ``` |
| 244 | ├── 00/ |
| 245 | │ ├── tweaks.tex |
| 246 | │ └── 0-DSC02432.jpg |
| 247 | ``` |
| 248 | |
| 249 | Note that this can both apply to a single spread as well as a set of |
| 250 | spreads, of example page or text colors are not reset automatically |
| 251 | and will affect all subsequent spreads until manually reset (in a |
| 252 | different spread's `tweaks.tex` file), while `photobook`'s tweaks apply |
| 253 | only to a single page. |
| 254 | |
| 255 | |
| 256 | #### Manual spread layouts |
| 257 | |
| 258 | If `layout.tex` is present it will be included as the page layout/template. |
| 259 | |
| 260 | Any paths in the `layout.tex` should be relative to the location the |
| 261 | built block .tex file will be located, usually to the project root. |
| 262 | |
| 263 | Template field substitution is done as for all other templates. |
| 264 | |
| 265 | |
| 266 | ### Templates |
| 267 | |
| 268 | A template is a LaTeX file with zero or more special fields defined. |
| 269 | |
| 270 | Field types: |
| 271 | - `${IMAGE}` / `${IMAGE<number>}` |
| 272 | Filled with image path. |
| 273 | - `${CAPTION}` / `${CAPTION<number>}` |
| 274 | Filled with caption file content |
| 275 | - `${TEXT}` / `${TEXT<number>}` |
| 276 | Filled with text file content |
| 277 | |
| 278 | Each field can be used more than once, the field value will be copied to |
| 279 | each instance. |
| 280 | |
| 281 | Multiple fields of the same type can be provided and each will be filled |
| 282 | with corresponding data in order, e.g. the third image filed will get |
| 283 | the third image path. Note that we are talking of field order and not |
| 284 | field number, this removes the need to constantly keep the field/file |
| 285 | numbers matched when adding and removing files/fields, all one needs to |
| 286 | do is keep the order the same. |
| 287 | |
| 288 | If a field is not filled it will be empty in the resulting `.tex`. |
| 289 | |
| 290 | Example template `templates/fullbleed.tex`: |
| 291 | ``` |
| 292 | \ImageSpreadFill{${CAPTION}}{${IMAGE0}} |
| 293 | ``` |
| 294 | |
| 295 | |
| 296 | ### Image captions |
| 297 | |
| 298 | In general image captions are decoupled from the main layout to enable |
| 299 | writers and editors to work on them externally. |
| 300 | |
| 301 | ```bnf |
| 302 | captions/ |
| 303 | ├── <image-name>.txt |
| 304 | └── ... |
| 305 | ``` |
| 306 | |
| 307 | The captions folder name/location is controlled by the `$CAPTION_DIR` |
| 308 | environment variable. |
| 309 | |
| 310 | |
| 311 | Inline captions are also supported: |
| 312 | ```bnf |
| 313 | spreads/ |
| 314 | ├── <spread>/ |
| 315 | │ ├── ... |
| 316 | │ ├── 00-<image-name>.<ext> |
| 317 | │ ├── 00-<image-name>.txt . . . . . . Local image caption |
| 318 | │ └── ... |
| 319 | └── ... |
| 320 | ``` |
| 321 | An inline caption must have the same filename as the corresponding image |
| 322 | but with a .txt extension. |
| 323 | |
| 324 | |
| 325 | ### Environment variables and configuration |
| 326 | |
| 327 | All the configuration options can be given in a configuration file as |
| 328 | well as environment variables. |
| 329 | |
| 330 | Environment variables take precedence over the configuration file. |
| 331 | |
| 332 | The default `make-images.cfg` would look something like: |
| 333 | ```shell |
| 334 | # if non-empty make-spreads.sh will add image paths to pdf notes... |
| 335 | ANOTATE_IMAGE_PATHS= |
| 336 | |
| 337 | # file extensions to treat as text (separated with "|") |
| 338 | TEXT_FORMATS=txt |
| 339 | |
| 340 | # file extensions to treat as images (separated with "|") |
| 341 | IMAGE_FORMATS=jpeg|jpg|png|pdf|svg|eps |
| 342 | |
| 343 | # default directory spread definitions are located in... |
| 344 | SPREADS_DIR=spreads/ |
| 345 | |
| 346 | # if non-empty link link images to matching ones from this directory... |
| 347 | # NOTE: this is ignored if --graphicx-path is passed or GRAPHICX_PATH |
| 348 | # is set. |
| 349 | IMAGE_HIRES_DIR= |
| 350 | |
| 351 | # directory where external captions are stored... |
| 352 | CAPTION_DIR=captions/ |
| 353 | |
| 354 | # root template directory... |
| 355 | TEMPLATE_DIR=templates/ |
| 356 | |
| 357 | # empty page template... |
| 358 | EMPTY_PAGE=emptypage |
| 359 | |
| 360 | # text page template... |
| 361 | TEXT_PAGE=textpage |
| 362 | |
| 363 | # image page template... |
| 364 | IMAGE_PAGE=imagepage |
| 365 | |
| 366 | # spread templates... |
| 367 | IMAGE_SPREAD=( |
| 368 | # |
| 369 | # +------- number of found images |
| 370 | # / +-- template name |
| 371 | # / / |
| 372 | [0]=text-spread |
| 373 | [2]=image-image |
| 374 | ) |
| 375 | |
| 376 | # if set (or --graphicx-path is passed) the images are identified by their |
| 377 | # basename so as to let graphicx package resolve the paths internally. |
| 378 | GRAPHICX_PATH=1 |
| 379 | ``` |
| 380 | |
| 381 | An explicit configuration file can be manually specified: |
| 382 | ```shell |
| 383 | $ make-spreads.sh -c <path> .. |
| 384 | ``` |
| 385 | |
| 386 | |
| 387 | --- |
| 388 | |
| 389 | `cls2tex.sh` |
| 390 | ------------ |
| 391 | |
| 392 | Extract the documentation from photobook.cls which is used to build the |
| 393 | photobook.pdf reference manual. |
| 394 | |
| 395 | This makes it possible to keep the documentation and code it describes |
| 396 | in the same place/file. |
| 397 | |
| 398 | The format is in part inspired by LaTeX's [.dtx](http://tug.ctan.org/info/dtxtut/dtxtut.pdf) |
| 399 | format but is far simpler and retains human readability with less effort. |
| 400 | |
| 401 | |
| 402 | ```shell |
| 403 | $ cls2tex.sh --help |
| 404 | ``` |
| 405 | |
| 406 | The `--help` says it all: |
| 407 | <!-- :r !cl2tex.sh --help --> |
| 408 | ``` |
| 409 | Generate docs from latex package/class |
| 410 | |
| 411 | Usage: |
| 412 | cls2tex.sh [OPTIONS] [[INPUT] OUTPUT] |
| 413 | |
| 414 | Options: |
| 415 | -h | --help Show this message and exit |
| 416 | -p | --prefix PREFIX |
| 417 | Set the doc comment PREFIX (default: "%") |
| 418 | -s | --strip Strip docs out |
| 419 | -n | --no-msg Don't add the "generated with" message to output |
| 420 | |
| 421 | This will: |
| 422 | - read the INPUT |
| 423 | - keep lines starting with \def\<module-name>@[A-Z]\+ |
| 424 | - keep lines starting with '%%' |
| 425 | - %%%%% Text -> \subsection{Text} |
| 426 | - %%%% Text -> \section{Text} |
| 427 | - %% >> code -> \begin{verbatim}code\end{verbatim} |
| 428 | - write the result to OUTPUT |
| 429 | |
| 430 | If no OUTPUT is given cls2tex.sh will write to stdout. If no INPUT |
| 431 | is given cls2tex.sh will read stdin. |
| 432 | |
| 433 | PREFIX can replace the second "%" in the above patterns to make it |
| 434 | possible to integrate multiple layers of documentation in one file |
| 435 | and to integrate them in various ways, for example, in the photobook |
| 436 | document class documentation "M" prefix is used to indicate |
| 437 | meta-command docs, this enables us to document them in the relevant |
| 438 | location (i.e. at the implementation) in source but move the docs to |
| 439 | a unified location in docs, effectively decoupling the source and doc |
| 440 | structure when needed. |
| 441 | |
| 442 | Strip mode is the reverse of of the default, it will strip out docs |
| 443 | and empty lines, keeping only the actual code and code comments. |
| 444 | |
| 445 | NOTE: stripping will not remove non-doc comments. |
| 446 | NOTE: the idea of keeping latex docs in a latex file is far simpler |
| 447 | than all the stuff crammed into .dtx, at least for my needs: |
| 448 | - keep the code readable |
| 449 | - keep the docs readable |
| 450 | in both the repo and in installed form, so .dtx is not used. |
| 451 | ``` |
| 452 | |
| 453 | <!-- vim:set ts=4 sw=4 nowrap : --> |