📜 ⬆️ ⬇️

How I left InDesign for LaTeX

InDesign is definitely the flagship in the layout industry. But, having worked there a considerable amount of time, I returned to the good old TeX, whom I met while I was still at university. Why did this happen? Why did I leave the markup language from an understandable WYSIWYG editor, and from a product supported by the most powerful Adobe company — a program whose code has long been frozen, and only new packages written by volunteers appear?

The story began with the fact that InDesign offended me by starting to blatantly lie to my eyes. I tried to make a name index and saw in it not the pages on which the “anchors” really stood, but slightly different ones. No dancing with tambourines helped. Making pointers by hand is not my genre. Writing your own scripts that will search for some additional hidden signs on the pages is also not a very reliable option. Especially since the list of tasks in the preparation of the publication was approximately as follows:

  1. make a thematic index
  2. make index,
  3. arrange a bunch of accents given that in the selected font, alas, the Unicode accent does not work,
  4. to ensure that these stresses properly migrated to footers, tables of contents and indexes,
  5. occasionally use structures like “see Footnote 15 on page 45 ",
  6. make spaces around the dash narrower, symmetrical, and the preceding dash is also inseparable,
  7. make an index of references to the Bible (sorted in order of biblical books, then by chapters, then by chapters).

At the same time, I wanted to maximally parallelize the tasks of working on the text and minimally use the Internet (the workplace is not in the city, but in the wilderness, where the Internet is barely alive).
')
Perhaps among the readers there are experts on InDesign who will tell you exactly how the above tasks can be solved. But in those decisions that I imagine, a lot of mouse movements, all copying and pasting. For example, in order to indicate where else the name I want in the index is found, I have to either re-enter it in the Index panel, or search for this treasured symbol of zero width in the document, copy it and paste it. The width is zero, but the height is not, and then you have to catch shoals that you have an interline crawl in the footnote because of this “miracle symbol”.

These numerous operations in manual mode scared me that, at that moment when it would be necessary to pass a mock-up, I would certainly have to urgently make some changes, respectively, something would go, something would have to be re-compiled, and out of a thousand things, which must not be forgotten, a hundred will be forgotten. In addition, this “not to forget” means that the layout put on the shelf must be frozen - the tricks will remain undocumented, and therefore, when re-published, they are unique (or, at least, painful).

Returning to LaTeX (more precisely, to XeLaTeX) was not easy. I had to figure out how to achieve the selected layout. I had to figure out how to achieve the above layout (so that the lines against the light coincided). I had to pull the author of one of the packages in order to make it possible to use Pantone (in some editions, part of the pages was printed in CMYK, part - in 2 colors: black and maroon). I had to learn the basics of several more languages ​​of communication with the computer: bash, perl, xindy, AppleScript, ...

But now there is some tools that can be shared.

So, the process of preparing the book is approximately as follows.

The initial document with the text and any footnotes opens in OpenOffice and through writer2latex is expelled in LaTeX, where it is carefully cleaned (there is usually full of all kinds of garbage). If desired, the document is divided into parts, but somehow it was more convenient for us to work with one common text file of the work.

Within the framework of the idea that it is necessary to separate the content and design, a separate header.tex file is created, into which a lot of package downloads and definitions of their commands are slowly being placed.

All changes and merging of versions occurs in Git, in our case in a private repository on bitbucket.org . When someone from the editors or proofreaders is afraid of these pieces, he edits as best he can and sends files by mail, but still someone sends them to the repository from the mail.

The geometry and fancyhdr packages are primarily responsible for the general layout view, and the fancyhdr for the look and layout of the headers (with its help I achieved the layout register ). Typographic delights can be achieved using the packages microtype and fnpct , which help to make the optical alignment on the edge and easy "drive" punctuation marks under the previous mark of the footnote. The footnotes themselves can be varied much more than in InDesign (at least on the field, even though all footnotes in one paragraph are merged) - this is footmisc . Drop caps (and the text wrapping image) are inserted using the lettrine package.

Until I ’ve gone far, the packages descriptions and examples of their use are on www.ctan.org. And a completely wonderful mutual aid platform - tex.stackexchange.com

The issue with the placement of stresses had to be solved like this:

 \usepackage{accentbx} \def\'#1{\upaccent{\aboxshift[.9ex]{^^^^00b4}}{#1}} \makeatletter \let\@acci\' \makeatother 

And with a dash - like this (this thing works in a dash, denoting direct speech:

 \usepackage{newunicodechar} \def\tire{—} \newcommand\vokrugtire{\hskip .1em plus .1em minus .05em} \newunicodechar{—}{\ifvmode\tire\kern .1em\ignorespaces\else\unskip\nolinebreak\vokrugtire\nolinebreak\tire\vokrugtire\ignorespaces\fi} 

LaTeX puts the shifts in general much better than the standard InDesign (although the module of Igor Vladimirovich Batov rather qualitatively corrects this deficiency of InD). But there is such a feature. In LaTeX, there is no “forbid page breaks” button. This is due to the fact that LaTeX first forms paragraphs, and then tries to distribute the lines among the pages. However, I didn’t use this button in InD - as it seems to me, it is necessary to prohibit only transfers from an odd page to an even page (that is, on the back of the page). When this button is turned on, InDesign also prohibits hyphenation between columns (in a multi-column layout), which seems to me quite brute force.

Games with hyphens are to vary the values ​​of parameters

 \righthyphenmin \lefthyphenmin \hyphenpenalty \doublehyphendemerits \finalhyphendemerits 

More details about these parameters can be found here . InDesign, of course, does not give such a degree of control over the process of the formation of a paragraph. And I had to deal with a situation where in InD a paragraph began to look disgusting because there was a ban on 4 translations in a row - but these 4 translations wouldn’t take a paragraph like the holes between words. So the approach of LaTeX with the calculation of the total value of the penalty seems to me very reasonable. Transports from an odd page can be caught using texttopdf and a perl script .

Working with pointers becomes very comfortable if you write something like this in the preamble:

 \usepackage{makeidx} \usepackage{multind} \makeindex{subj} \makeindex{name} \newcommand{\subj}[1]{\index{subj}{#1}} \newcommand{\name}[1]{\index{name}{#1}} 

Then in the text it will be possible to insert each time on a separate line, repulsed with several tabs (so as not to merge with the main text stream \subj{...} , then chase
sed -n "/\\\name/p;/\\\geo/p" main-file.tex | sed "s/|[)(]//g" | LANG=ru LC_COLATE=C sort | uniq > name-and-geo-index.tex
and without any compilation of the file, see the draft index, from which then simply take and copy into the main file those pointer slots that are needed again. For a complete compilation, you will have to figure out the xindy settings and, perhaps, do some work yourself. But I managed to make in the book a single geographical index, in which there are both page numbers and squares of attached maps. And also I taught the nests of lower levels not to leave widows nest parents (in InDesign this cannot be achieved in styles using Keep with next / previous: either all children stick to a single block, or a blue parent sticks to the next parent).

And if you do the bibleref package in the correct way, you can achieve that when you add a line to the main file, \bible{. 1:1} \bible{. 1:1} at the end of the book there will be the “Index of references to the Holy Scriptures” chapter, where in the “New Testament” section there will be a subsection “The Gospel of Matthew”, and there the line is 1: 1 ........ (page number) .

If in this paragraph you are ready to flare up and exclaim, “Oh, these churchmen! Even on Habr snuck! ”, Then wait a minute, now let's move on to the most interesting - how to work with pictures (noticing in brackets that TeX is absolutely perfect for imposition of Church Slavonic texts ).

InDesign typically drives a picture into a layout like a nail into a wall - it should stand here, and let the text flow as it wants. TeX perceives pictures as floating objects, about which the user says: "A picture would be nice somewhere here, at the top of the page (or below, or no difference)." And the picture does not float away from the text to which it is attached (even if you are told to cut the page width by two centimeters half an hour before the delivery of the layout). It is possible to achieve and that the picture appeared on the nearest right lane:

 \newcommand{\kartinkavramke}[1]{\fboxrule=2pt\fboxsep=0pt {\centering\boxkinovar{\includegraphics[height=\textheight]{#1}}\par}} \newcommand{\kartinkavskoresprava}[1]{ \ifodd\value{page}\afterpage{\kartinkavskoresprava{#1}}% \else\afterpage{\thispagestyle{empty}\noindent% \kartinkavramke{#1}}\fi} 

In the above code, the problem is also solved at the same time, so that on a page containing only a picture, there is neither a footer nor colonization numbers.

Well, for TeX it is not a problem to include a list of illustrations in the book (moreover, elements of this list can be made different from the signature under the illustration itself). In InDesign, for this, it would probably be necessary to put boxes with white text that necessarily fall on the page (lying on the side of InDesign does not include indices).

LaTeX accepts a rather limited list of graphic formats: PDF, JPG, PNG. No tiff to you, no psd. It does not relax, but does not interfere with life. For compilation speed, you can make two directories for images: large and large .

 cd large for i in *.*; do echo $i; convert -resize 25% -quality 60 $i ../small/$i; done 

And in the text itself, temporarily use

 \newcommand{\pathtoimg}[1]{small/#1} \includegraphics[height=\textheight]{\pathtoimg{myself.jpg}} 

Even the smartest machine can not do everything the way a person would like, and in the end you still need manual refinement (which somewhat destroys the idea of ​​separating content from design - but this can be diluted at the level of Git branches). It is necessary to engage in forcing and driving to achieve a beautiful view. From the part of the work can save this trick:

 \setlength{\parfillskip}{0pt plus .75\textwidth} 

which means “I want the last lines in a paragraph to be filled no less than 25%” in Russian. The rest of the work will have to be done with the help of the usual techniques: changes in tracking and interword spaces.

 \newcommand{\tracking}[2]{{\addfontfeature{LetterSpace=#1}#2}} \newcommand{\interword}[2]{{\setlength{\spaceskip}{#1\fontdimen2\font plus #1\fontdimen3\font minus #1\fontdimen4\font}#2}} 

What can not but rejoice here is that the layout designer can see everything: where are the tools that are used (InDesign has tracking backlight mode, but the value at each point can be different until you plug it, you don’t recognize it).

What can not but grieve is that after each parameter change, you have to re-compile the document in order to see whether it turned out or failed. If the document is huge, it can take a couple of minutes. But even here there are tricks: you can use \includeonly{...} or write your own commands, forcing LaTeX to compile only the necessary fragment, and skip the rest.

And now we come to the most difficult stage - the delivery of the layout to the printing house. To begin with, we will need an indent (bleed) of 5 mm. You are welcome:

 \usepackage[ layoutsize={140mm,200mm}, papersize={150mm,210mm}, layouthoffset=5mm, layoutvoffset=5mm, ...]{geometry} 

Then require forcing in PostScript and sweep through Adobe Disttiller. I tried to do it in two ways.

cupsfilter -P "PrintDriver.ppd" -m "application/postscript" my-book.pdf > my-book.ps and pdftops my-book.pdf my-book-another-way.ps . But it turned out some nonsense. Black text after running through cupsfilter (or pdftops ), and then through Distiller turned into composite CMYK. I had to use Adobe Acrobat Pro: open and save as PostScript. So black has kept his purity.

Not to do it by hand, wrote a little AppleScript:

Hidden text
* acro-pdf-to-ps.scpt *
 on replace_chars(this_text, search_string, replacement_string) set AppleScript's text item delimiters to the search_string set the item_list to every text item of this_text set AppleScript's text item delimiters to the replacement_string set this_text to the item_list as string set AppleScript's text item delimiters to "" return this_text end replace_chars on run argv set current_path to "/Volumes/data/process_me" set in_file to current_path & "/" & item 1 of argv set out_file to replace_chars(in_file, ".pdf", ".ps") set in_file_correct to POSIX file in_file set out_file_correct to POSIX file out_file with timeout of (8 * 60) seconds tell application "Acrobat" activate open in_file_correct save document 1 to out_file using PostScript Conversion close document 1 end tell end timeout end run 

* acrodist.scpt *

 on run argv set current_path to "/Volumes/data/process_me" set opt_file to current_path & "/Typo.joboptions" set in_file to current_path & "/" & item 1 of argv set out_file to replace_chars(in_file, ".ps", "-distilled.pdf") with timeout of (8 * 60) seconds tell application "Acrobat Distiller" Distill sourcePath in_file destinationPath out_file adobePDFSettingsPath opt_file end tell end timeout end run 

 osascript acro-pdf-to-ps.scpt my-book.pdf osascript acrodist.scpt my-book.ps 


All these scripts pursue one goal: if at the last moment they say something to change, then the stream through which these changes will be included in the final upload of files should be debugged. Especially if there are several files.

So the transition from InDesign to LaTeX took place. Most likely, irrevocable (if you do not have to type out magazines with a bunch of pictures). With your joys. With their sorrows. With a bunch of discoveries. Which is ready to share - write, ask.

As they say, happy TeXing!

Source: https://habr.com/ru/post/310344/


All Articles