**Typesetting Markdeep Output in InDesign**
Andrew Glassner
@AndrewGlassner
http://www.glassner.com
February 7, 2018
New Chapter Layout Cheat Sheet
====
This is up here for quick reference. The document below explains what's going on.
1. Open Chxx-Master. Change header. Right-click filename and change Master options to use Chxx prefix (xx is current chapter).
1. Go to NewChap-Master. Update chapter number, title, and blurb.
1. On Chapter splash page, update the graphic. Also show Layer 3 and update the chapter number and name for the book TOC, and then hide the layer again.
1. Place saved Word .docx file. Shift-click in the master text frame on a blank page.
1. Select all. Apply "body" paragraph style with overrides (*not* character overrides).
1. Deselect all.
1. Delete Paragraph Styles from Word (often "Normal", look for the import icon at right)
1. Delete all "Strong" character styles, replace all with body-bold.
1. Delete all "Emphasis" character styles, replace all with body-italic.
1. Delete all "HTML-Code" character styles, replace all with body-code.
1. Delete any other Word character styles.
1. Open the Markdeep output and scroll up to the Table of Contents so you can see the headings and their numbers. Scroll through the InDesign document and select each head and sub-head. Insert the head number at the start of the line (e.g., 16.1). Right-click on Heading 1 or Heading 2 and choose Apply with Clear Character Styles (because Markdeep sets these in bold, which is good as it makes them easier to find in this step).
1. Select all references at end. Set Char style to None. Then assign Reference PPH style.
1. Select all image credits at end. Set Char style to None. Then assign Image Credit PPH style.
1. Apply search and replace rules below.
1. If there are URLs in the Image Credits, manually select each and set it to the Image Credit URL Char style.
1. Format code blocks if present.
1. Place images. Refer to the Markdeep output (with files displayed) to identify which file goes with each caption. Be sure to remove any extraneous paragraph breaks before captions (use Type/Show Hidden Characters if needed). Instead of white space, use text frame controls to assign white space above and below.
These are all entered using the "GREP" mode in the search and replace dialog. These use Chapter 5 for illustration, so replace the 5 with the chapter number being edited. If you're using automatic numbering, you can use InDesign's built-in marker.
Purpose | Search for | Replace | Other
----------------------------------|---------------|-----------|-------
Remove extra paragraph breaks | \r\r | \r |
Change "Figure 3" to "Figure 5.3" | `Figure~S` | `Figure 5.` | Make sure the search is case sensitive
Set captions with styled naming | `Figure 5.\d+:` | | Char style = Figure number, Pph style = Caption
Set URLs using the URL style | `http.*?[$ ]` | | Char style = URL
What This Document Is
====
This document is a guide to converting book chapters
written with Markdeep into a final book
produced with Adobe's InDesign.
This is not a tutorial on either system.
Rather, it's just a summary of the workflow
that I found worked well for me.
Customize what's here for your own project.
The Big Picture
====
Markdeep is wonderful
for writing and editing.
Though Markdeep's output can be made very
nice with creative CSS choices,
the final results are
ultimately limited by the layout
and typographic
capabilities of the browser that
displays the final output.
That's not an issue for web content.
But for my book,
I wanted more typographic finesse,
and more manual control over the layout,
than I could coax out of a browser.
Why Layout at All?
----
The point of this workflow is
to create pages that look just
the way you want the reader to
see them.
My target is Amazon's Kindle
format.
Normally on Kindle you can choose
the type face and size,
but with this workflow the reader
will *not* have those choices.
In other words,
this will not be a typical Kindle
book that can be "re-flowed" on the
fly by Kindle.
Instead, we'll use Adobe's free
Kindle Textbook Creator (KTC) to create
the Kindle file.
This takes a PDF as input,
and conceptually packs up each page
as a single Kindle object.
Everyone who looks at this book will
see the same typeface at the same size,
with the pages set in the same way.
I chose this route because my book is
graphics intensive, and I cared a lot
about where those figures were located.
A downside of this approach is that,
with the exception of a few Amazon devices,
there will be no active hyperlinks in
the Kindle file.
So if you have URLs in your text,
readers will need to select each one
they want to follow,
copy the text, and then paste it into
a browser.
It's a drag,
but it's a limitation that Amazon
has placed on the Textbook Creator.
It's confirmed in
question 35 on the KTC page
at https://www.amazon.com/gp/feature.html?docId=1002998671.
Maybe by the time you read this they'll have
changed their policy and made hyperlinks work.
If you're more flexible about
your layout than I was,
you can probably use one of Adobe's other
Kindle conversion tools.
Then your book will be more like a
"typical" Kindle book,
where the reader can choose the
typeface and size,
and can even select the type itself.
But figures and other elements will
show up where Kindle decides to dynamically
place them,
which can become a source of
reader frustration.
If your mathematics and
graphics needs are light,
and your book is mostly text,
then I recommend skipping InDesign
altogether and instead using the
wonderful Vellum .
Why InDesign?
----
For my deep learning book,
I wrote each chapter as a standalone document
in Markdeep.
When I was done writing and editing,
I wanted to lay out the book using
traditional book layout tools.
I considered LaTeX, Quark, and InDesign.
For this book,
LaTeX wasn't a good choice.
I wanted to control the aesthetics
visually and directly,
not by trying to wrangle a
parameterized layout engine.
It helped that
I didn't have any equations to set.
That left Quark and InDesign.
Some online research online suggested that
InDesign now rules the book layout world.
Since I'd signed up for an Adobe
subscription for Photoshop and Illustrator,
I had InDesign already at my disposal
(though it worked out nicely for me
in this case, I still dislike
the software subscription model).
Learning InDesign
====
This isn't an InDesign tutorial,
but if you're brand-new to the
product (as I was),
here are some hints for getting started.
Adobe's introductory tutorials are
surprisingly good.
Go to
and go through the videos in
"Get started with InDesign."
There's 10 of them,
and they're worth your time.
I watched them at 1.5x speed.
I also downloaded the files and
replicated every step,
so I'd have it in my fingers,
and I found that useful.
Unfortunately,
there are only 10 videos,
and there's a lot more to know.
There's probably a great book or
site out there,
but I learned by searching for
one topic at a time
when I got into trouble.
Most of what's out there is of
the "To do X, click here, and then here"
variety,
so you don't learn *why* you're
doing what you're doing.
This makes it hard to figure out
what else you can possibly do,
and then how to do it.
This also makes it hard to debug your
workflow when things go wrong.
The best I could manage was to find
a site or two that would tell me how
to do something close to
what I was trying to do,
and then by comparing their steps to
mine I could discover where I went wrong,
and thereby learn a little more about
how InDesign wants us to think
when using it.
So here's some general stuff that
I wish I'd known.
Setting Up the Styles
====
For a project like this,
**it's all about the styles.**
The styles rule.
Spend a lot of time on your styles
until you've covered everything
you want to typeset,
and it looks the way you want.
I spent 3 or 4 days with my first
chapter,
coming up with paragraph and character
styles, changing them,
deleting them, making new ones,
and so on,
until I was happy with my pages.
Truly, I spent days on this.
And in retrospect, I should have
spent another day or two.
As I went on,
I ended up tuning these styles
a little bit now and then,
and creating styles for formatting
that I needed but which wasn't
present in Chapter 1.
Once you have your styles set up,
laying out the book goes fast.
But every time you need to do something
you didn't anticipate
(like set a block quote,
or an occasional sidebar),
your workflow grinds to a dead stop
and you spend time futzing with the
style mechanisms.
In other words,
you've gone from making layout decisions
to making design decisions,
and that's a huge mental shift.
Save yourself the trouble.
Make a sample chapter with everything
in your book.
Heads and subheads,
figures and tables,
code listings,
and so on.
If you want a splash page for
your chapter,
and a table of contents,
include those too.
Refine and refine your styles until
everything looks right,
and there are no special cases that
you had to adjust by hand
(other than page or column breaks).
The closer you can get to having your
final styles set up and ready,
the easier and more fun layout will be.
In my Markdeep, I didn't use any of the
fancy features for creating diagrams and
calendars and so on.
I stuck to bare bones:
chapter title, first- and second-level heads,
figures with captions,
code listings with captions,
and references.
Paragraph Styles
====
Main Styles
----
These are the styles for the main
body of the text.
Paragraph Style | Purpose
--------------------------------|---
Subhead 1 | Top-level heads
Subhead 2 | Second-level heads
Caption | Figure and listing captions
body | Main body text
Reference | A cited reference, usually at the chapter's end.
Image credit | The source of an image, usually after the references.
Notebook path | The name and path of a Jupyter notebook with code.
Block quote | A block quotation
Python Styles
----
I've got some Python code in the book.
My listings have a black line above and below,
which I create using the border option in
paragraph styling.
I have three types of Python lines:
the first (with a border above at some
extra distance),
the last (with a border below at some
extra distance),
and all other lines (which I call "mid").
I wanted to distinguish lines of input
from lines of output.
So there are two versions of each
of input, mid, and last.
They are identical except that the
input versions have one color of
background, and the output versions have
another.
I also have a special style for one-liners,
which have both the before and after borders.
There's also special styles for lines
that are comments,
and when the first
line of input is a comment.
Python (folder) | Purpose
--------------------------------|---
Python Input First | First line of a listing of input
Python Input Mid | An internal line of a listing of input
Python Input Solo Line | A one-line Python listing
Python Input Mid-Comment | A full line of comment inside a listing
Python Input First-Comment | A full line of comment appearing at the start of a listing
Python Input Last | Last line of a listing of input
Python Output First | First line of a listing of output
Python Output Mid | An internal line of a listing of output
Python Output Solo Line | A one-line output listing
Python Output Last | The last line of a listing of output
To keep these all consistent,
I use "master" styles.
These are not a formal InDesign thing,
but just a trick I picked up on the web.
Basically I made a "master" style for
input and output lines.
They held my choice of font family,
size, leading, and background color.
I never use these styles directly,
and tuck them away in a folder.
Then I created the actual styles I used
by creating styles that are "based on"
these masters,
using that field in the paragraph style
creation dialog.
That way the styles just save what's
different relative to the "master."
In my case, it was just any borders
that needed to be added.
PYTHON MASTERS (folder) | Purpose
--------------------------------|---
Python Input MASTER | The master for input lines
Python Output MASTER | The master for output lines
Per-Chapter Styles
----
Every chapter has a title page.
Here are the styles I use on that page.
Per Chapter (folder) | Purpose
---------------------|---------
Chapter Title | The title
Chapter Number | The chapter's number
Chapter Summary | A short description
Running Head | The per-page header
Hidden Chapter Name for TOC | See the TOC section below
TOC Styles
----
InDesign lets you create special styles
for the Table of Contents it can automatically
generate for you.
I use three styles:
TOC styles (folder) | Purpose
---------------------|---------
TOC level 1 | Top-level headers
TOC level 2 | Second-level headers
TOC Hidden Chapter Name | see below
The two styles referring to
"Hidden Chapter Name" are a well-known
InDesign trick.
On my Table of Contents,
I want the chapter's name and number
to appear on a single line before the
contents of that chapter.
Since I'm using automatic page numbering,
but not automatic chapter numbering,
there's no convenient way for me to get
the chapter number and title and automatically
create the corresponding TOC entry.
So instead the opening page of each
chapter has an extra layer.
On that layer I place the line I want
to see in the TOC,
for example, "2: Songs About Dogs".
Then I format that with the
"Hidden Chapter Name for TOC" style,
and then *I hide the layer*
by turning off the eye icon in
the layer list.
Later,
when I generate the Table of Contents,
I choose the option to "include hidden layers."
Voila, the name gets picked up and correctly
formatted.
Character Styles
====
My character styles are smaller in
number and more focused in purpose.
Here are their names and where I use them.
Character Styles | Purpose
---------------------|---------
Body Char Style | Default body
URL | A URL, usually in the references
Image Credit URL | A URL inside an image credit
Caption Figure Number | The phrase "Figure X:"
body bold | Bold text
body italic | Italic text
body code | Code fragments in the text
Glossary Keyword | A keyword in the glossary
Database Name | The name of a database
The last two entries are specialized styles
for the unique needs of two chapters.
Master Pages
===
Each chapter has two master pages.
They're saved as single pages,
not spreads,
since Kindle presents one page
at a time.
The first master is the splash page.
It's got the chapter number and name,
a blurb,
some graphics,
and the chapter number and name for
the Table of Contents on a hidden layer.
The other master page has a header
(with the chapter name and number),
a page number in the bottom-right,
and a big text frame for the text.
InDesign does crash sometimes. Save periodically.
The Style Reference
====
I made an empty document to serve as
my style reference.
If I ever updated a style,
or added a new one,
I made sure to add it to this document.
When the book is done,
you can format all the chapters
using the styles in this document.
Or you can manually copy its styles
into each chapter by opening the
chapter,
going to the Paragraph Styles menu,
from the flyout choose "Load Text Styles..."
and choose the style master.
Select "Check all" to import all
the styles and click OK.
My style reference contains
the two master pages above.
They will need to be customized
for each new chapter.
It also holds three blank,
normal (that is, not master)
pages.
The first is assigned the chapter
splash master.
The second and third have the
body master assigned to them.
There's two of these because the
first will ultimately hold that
chapter's Table of Contents,
so I leave it blank during layout.
The chapter body starts on the second
blank page.
I also set up the style for my
Table of Contents,
and save that.
InDesign treats these TOC styles
differently from the other styles,
so they need special care.
I just set it up once and save it
as my "Custom TOC Style."
Choosing that from the Layout menu
makes sure that it's the style
that gets used from then on by default.
The Process
====
Here's how to make a Kindle-ready
book in InDesign using Markdeep source.
I'm on a Mac so some of this will
refer to Mac stuff,
but it should all be perfectly
applicable to PCs.
Prep InDesign
----
Open the style master.
You should have two masters (one for the
splash page, one for text pages).
In the page master, change the running head to the current
chapter number and title. Change the name of the master
(I use things like "Ch06-Master').
On the splash page master,
set up the chapter number, title, and blurb.
Confirm numbering. Double-click the arrow
above the first page (in the Pages list)
and choose "Automatic Page Numbering" from
the choices at the top of the dialog.
This lets the pages get numbered from 1 to
the end of the book when the files are
assembled into a complete book
(using InDesign's "Book" features).
The style master should have
three non-master pages.
If they're not there, make them.
The first page is the splash page,
and is formatted using the splash master.
On the splash page (not the master),
unhide the layer with the chapter number and title
(used only for the book's table of contents),
update that text, then hide the layer again.
Make sure to
Select layer 1 when that's
done so that you'll be talking
to an active layer going forward
(otherwise mysterious things will happen.
If you can't paste text into a page later,
make sure that Layer 1 is the active layer).
That's it for the chapter setup.
Do *not* touch the second and third
blank pages,
which have the default page master
applied to them.
Instead, save this file with a new
name, like "Chapter 12",
and let it sit for a moment while
we prepare the text in Microsoft Word.
Word Stuff
----
Now we're going to put our text into
Word,
set things up,
and save the document.
Open your Markdeep file in your favorite browser.
Make sure you've turned off development
features like the display of filenames
for figures
(I only disable them temporarily because
they're of great value later on).
Select all, and copy.
Go to Word, select "Blank Document",
and then paste your clipboard.
If you have figures,
Word will give you a dialog box
called "Grant File Access" for
each and every figure.
You do **not** want to import any
figures at this point.
Press **Cancel**.
And do that over and over again,
once for every figure,
and again at the end for some reason.
Your text should now appear in your
Word document,
without figures.
Don't worry about the formatting,
since we'll be changing it all.
Now we're going to set up some
styles so that bold, italics, and code
will carry over into InDesign.
When we paste our text into InDesign,
the bold, italic, and
fixed-width (code) words won't have
special formats associated with them.
They still show up with those attributes,
but we want them to actually have our
styles so we have control over
their appearance.
To keep bold, italic, and code words
as we want,
we will ultimately need to tag each one
with the appropriate InDesign character style.
That way all bold words (for example)
will be formatted the same way,
and if you later want to tweak your formatting,
you only need to change the bold style and all the
bold words will automatically adjust.
The same thing will be true for italics
and fixed-width code.
The trick is to get those InDesign
character styles associated with the words.
Doing it manually is boring and error-prone.
But it turns out that when InDesign imports
a Word document,
it also imports Word's styles,
and it keeps those styles associated with
words they've been applied to.
So our goal is to get Word to attach a
style to every bold word,
and another style to every italic word,
and another style to every code word.
We'll use Word's find-and-replace
mechanism to find all the
words that are formatted in bold,
and attach a character style to them.
We'll do the same thing for italics,
then code.
We'll need to do a little adjusting
of the styles after importing to InDesign,
but it's a quick one-time thing,
and far easier than manually setting the
style for every formatted word in the chapter!
There is some weirdness here,
so follow along in Word.
From the "Edit" menu,
choose "Find", then "Advanced Find and Replace...".
There's a little down arrow in the bottom left.
It's unlabeled (sigh).
If there's nothing below that arrow, click it.
You'll get another panel at the bottom of the
dialog with a region called "Search"
and one called "Find."
At the top of the window,
choose "Replace" (it's the middle of three buttons).
**This is important and weird**: Click in the
field to the right of "Find what:".
This makes sure that the region at the bottom,
which should read "Find", really does.
In the "Find" region there is a "Format" drop-down.
Click it and choose "Font..."
From the dialog that appears,
choose "Font" from the button bar at the top.
Here we will *leave everything alone*,
but specify *only* the one thing we want:
bold text.
Under "Font style:", choose the drop-down.
Select "Bold."
And that's it. Click "OK".
Back in the Find and Replace dialog,
click in the field to the right of "Replace with:".
**Notice the weirdness**: The field at the bottom
of the dialog now reads "Replace."
Because obviously.
Again, choose the "Format" drop-down,
but now choose "Style..."
You'll get a new dialog box called "Replace Style."
Scroll down until you find "Strong"
and press "OK."
Back in the Find and Replace dialog,
choose "Replace All."
Bam! Every word in the text that
is in bold
now has a style of "Strong" associated with it.
Word should give you a little pop-up
telling you how many changes it made.
This operation might also change the font,
or font size,
or other attributes.
Don't worry about it,
since we'll be replacing all of
those things in InDesign anyway.
Repeat the process,
choosing "Italic" for the font
description in the Find format,
and "Emphasis" for the style
description the Replace format.
Hit Replace All again.
Finally, repeat again.
This time we want to find
all words in fixed case
(find one and see what font
it uses; on my system it was
"Courier New").
In the Find dialog,
choose this font
(don't choose italics or bold),
and hit OK.
In the Replace dialog,
choose the "HTML Code" style.
Again, Replace All,
and the fixed-width words in the
text are now formatted.
This will also set this style
to the lines that are in Markdeep's
Listing blocks.
Don't worry about it,
since we'll be over-writing
those styles manually in InDesign.
For me, that's 99% of my
text formatting,
so that's all I do.
Save the file as a native
Word file in .docx format.
You can close or quit Word now.
You're done with it until you're
ready to process the
next chapter.
Importing into InDesign
-----
You should be at the third page in
InDesign: a blank page with the
chapter's default style assigned to it.
**Do not do anything to the text frame on this page.**
Don't click on it.
Don't control-click on it.
Don't touch it at all.
If you select this frame,
it will "disconnect" from the master.
That basically means that our text
won't go into the frame,
and it won't auto-flow,
and it won't make more pages.
And if you're like me,
you'll go nuts trying to figure out why.
If those things happen, it's because
you clicked on the text frame.
I find the best thing to do is to
simply delete the page by dragging
it to the trash.
Make a fresh new page and assign
the body text master to it.
Don't click the text frame!
Looking at this page,
choose "File" and "Place..."
(or press command-D on Mac).
Choose the .docx file we
just saved from Word.
Turn off all the checkboxes.
If you get a warning about missing
fonts,
ignore it and press "Close."
We're going to replace them all
soon anyway.
Now take a leap of faith.
You can't see the text frame.
But it's there.
Your cursor should be "loaded,"
or showing a tiny bit of text.
Press the Shift key,
which should superimpose a
U-turn arrow on the icon,
showing that the text will autoflow.
Now, with the Shift key down,
click anywhere near the middle of the page.
If all is well,
your text frame should fill up with text.
**Wait.** It may take a few moments for
InDesign to create more pages and then autofill
them with text for you.
It won't show you those pages in the Pages
menu until this process is done,
so give it a moment. Just a few seconds is
enough for 40-50 pages on a 2014 iMac.
Bigger files and slower computers will take longer.
I expected this process to be
instantaneous and caused all kinds
of problems by clicking here and there,
trying to wake up what I thought
was a sleeping InDesign.
Be patient.
If you don't get lots of new pages
within 5-20 seconds,
you may have accidentally disconnected
the text frame from the master.
As described above,
throw out the page,
make a new one,
and try again.
Applying InDesign Character Styles
----
Now we'll pick up the character styles
we set up in Word.
Click in your text and
use "Select All" to
select everything, and in
the Paragraph Styles dialog,
find your body style.
Mine is called simply "body."
Right-click on that style and
choose "Apply body, Clear Overrides."
(where "body" will be your style's name).
Do **not** pick "Clear Character Styles"
or you'll lose all the bolds, italics,
and code.
Now everything should look like
your body style.
Deselect everything.
You may notice a bunch of
paragraph styles in the Paragraph Styles
panel named things like "Normal_wrd_1",
"Normal_wrd_2," etc.
You can (and probably should)
just delete them by selecting them
and pressing the trash can option.
It will offer to replace them with
some other style,
just say "OK" to whatever it suggests.
Make sure that you have the selection
tool selected (the topmost, black arrow),
and no text is selected.
Open the Character Styles palette.
You should see an entry called
"Strong",
corresponding to the style we assigned
in Word.
There might also be more versions of
this, like "Strong_wrd_1",
"Strong_wrd_2",
and so on.
Select all the "Strong" versions,
and press the trash can icon in that panel.
InDesign will prompt you with the
style to replace them with.
Choose your body's bold style
(mine is called "body bold").
Check the "Apply to All" checkbox.
Press "OK."
Now all your bold words are set
in "body bold."
Repeat this for the "Emphasis"
styles in the Character Styles palette,
replacing them with your italic style
(mine's called "body italic").
Repeat once more, turning all of the
"HTML Code" words into your code
style (mine's "body code").
While we're at it,
go to the Character Styles palette
and look for a folder named something like
"Styles for Word/RTF Imported Lists."
If it's there,
delete that folder and everything inside it.
Also delete any other Word styles in either
the paragraph or character style palettes.
Save!
Style InDesign
----
I go through the document now in
two passes.
First, I set the styles for my heads
and subheads,
and then I set the captions.
To set the heads and subheads,
it helps a *lot* to have the Markdeep
output open on a browser nearby.
That's because when you selected your
text from the browser way back at
the start,
you didn't get the section numbers,
because browsers are weird.
This means you need to put them back
in by hand.
Referring to the Markdeep output
helps you to keep track.
So scroll in your browser to the
top of the file, so you can see your
Table of Contents, and move
that browser window to the side
where you can still see it.
Returning to InDesign,
if you've copied and pasted
Markdeep's table of contents
into your InDesign file,
delete it,
since you'll want to use
InDesign's built-in
ToC generator.
For each head and subhead
in the InDesign file,
we need to do three things:
1. Insert a number
1. Turn off character styling
1. Assign a paragraph style
Find your first head or subhead.
Insert a number before the head.
For instance, if it's the fourth head
in Chapter 3, I'd put 3.4 at the start
(I follow that with two spaces for aesthetics).
Subheads get an extra number,
like 3.4.2.
Select the whole line with the head
or subhead (triple-click does the job,
or just sweep over the line to select
all the text).
The heads and subheads come in with
bold styling attached,
so now they have the "body bold"
character style on them.
We want to get rid of that
(recall that because character styles
are applied after paragraph styles,
applying the heading paragraph style
will not remove the bold).
Now right-click your heading style
(I use "Subhead 1" and "Subhead 2")
and choose "Apply Clear Character Styles".
This will set the head to have just
our paragraph style.
When I've numbered and styled all
my heads,
I style the captions.
First, I make sure the figure
numbers are set up as I want.
Markdeep numbers the figures starting
at 1 and ascending,
which is great in a standalone document.
But if I'm setting Chapter 5,
I want the figures to be numbered
5.1, 5.2, and so on.
So open "Edit" and "Find/Change..."
Choose "GREP" from the button bar.
In the "Find what:" field,
enter "Figure~S". The tilde followed
by capital S means "normal space".
In "Change to:', Type "Figure 5."
with a trailing period and no trailing space
(use the appropriate chapter number,
of course).
Now every instance of "Figure 1"
becomes "Figure 5.1",
every "Figure 2" becomes "Figure 5.2",
and so on.
Now let's assign the caption style.
We're going to kill two birds with
one stone now.
We'll use find and replace to find
every caption and set it with the
"Caption" paragraph style.
At the same time,
we'll apply a little bit of finesse.
My captions begin with "Figure 5.3:"
(now that we added the chapter number
above), and I'd like that to be a
little bit bolder than the caption.
The trick to setting both the caption
style and the bold start at once
works because InDesign always applies
the paragraph style first,
then the character style.
So we'll search for a string
of the form "Figure 5.13:"
where the 5 refers to the current
chapter number (thanks to our recent
substitution),
and "13" stands for any string
of digits.
We'll apply the Caption Figure Number character
style to make it stand out.
And we'll apply the Caption paragraph
style as well.
The Caption style will apply to the
entire paragraph this string is part
of (that is, the whole caption).
This only works when
the caption is just one
paragraph long.
If a caption has more than one
paragraph,
you'll have to go in and apply
the formatting to the
additional paragraphs by hand.
To assign the styles,
open "Edit" and "Find/Change..."
again.
Choose the "GREP" button again.
In "Find What:",
we'll look for all instances
of "Figure 5.x:",
where we're supposing you're
editing Chapter 5,
and x stands for any digit.
We express "any digit" using the
sequence \d.
But we want to match not just
single digits,
but multiple digits (like in Figure 5.12).
We express that by placing a "+"
after the digit sequence,
meaning "one or more."
So type `Figure 5.\d+:`
(make sure to include the colon,
because we only want to modify
the starts of captions,
not places in the text where we
refer to the figures).
Make sure the "Change to:"
field is empty.
At the bottom of the dialog,
click in the "Change format" box.
In the new dialog that pops up,
make sure "Style Options"
is selected from the left.
On the right, choose the pop-up
next to "Character Style:",
and choose "Caption Figure Number."
In the pop-up for "Paragraph Style:",
choose "Caption."
Press OK.
In the Find/Change dialog,
press OK.
You should get a dialog box
telling you how many changes were made.
Save!
URLs
----
I like to typeset the URLs in a
different typeface,
so I've defined a character style called
URL.
In search and replace,
I choose the
GREP tab and enter
`http.*?[$ ]`.
for my search pattern,
and choose "URL" for the
replacement character style.
This matches anything starting
with `http` (including `https`),
and works forward to the first space
or the end of the paragraph.
If you use URLs that don't
start with `http`,
you'll need to craft your own search
string to fit your approach,
or find and style them manually.
Code
---
As discussed above,
I have multiple styles for code,
depending on which line I'm
formatting.
I use paragraph styles,
since each line of code is
terminated by a carriage return
(making it a one-line paragraph).
To format a block of code,
I usually select all the lines,
apply "Python Input Mid" paragraph style with
"Clear Character Overrides" to
all of them,
and then apply the first and last
line styles individually to the
first and last lines.
If the "block" is just one line,
I use one of
the one-line versions.
Unfortunately,
quotes are a PITA.
Word uses "smart quotes" for the
body text,
which is great,
as it gives us opening and closing
quote marks.
But we don't want that for code,
where we usually have the same
character for both opening and
closing quotes
(whether it's a single quote mark or a pair).
After I've applied my styles,
and my code is all in code font,
I do another "advanced" search and
replace.
I start by finding the quote mark I want
from the "Glyphs" panel and pasting
it into my document.
I copy the opening smart quote
from typeset code
and paste that into the "Find" box.
In the search format,
I specify the code font.
Then I copy the desired quote
I just put into the document,
and put that in the replace field.
Replace all.
Now copy the closing smart quote
from typeset code,
paste that into the find box,
and replace all again.
That's it for basic styling.
Now we can insert figures.
Inserting Figures
-----
Markdeep offers a fantastic option that
helps in this stage.
By including
the following line in your
Markdeep source file,
your output will have a table of contents
(which helps you assign header numbers,
as discussed above),
and every figure will include the
name of its file in its caption.
~~~
markdeepOptions = { showLabels: "true", tocStyle: "long"};
~~~~
The file names are of enormous value,
because now you can scroll through the
Markdeep output in the browser,
and the InDesign file next to it,
in tandem.
Each time you reach a caption in the
InDesign document,
just look at the Markdeep output to
read off the file name,
and use the Place command to insert that file.
The only tricky thing here is that you
want to set `showLabels` to `false` before
you copy your text and paste it into Word,
or else you'll get the file names in your Word
document and then your InDesign,
and then you'll have to delete them all.
So temporarily turn off the labels,
refresh the browser,
copy everything and paste into Word,
and then turn labels back on.
Always use the Place command (Control-D on Mac) to place
graphics.
This makes sure that InDesign knows where the source
image is located,
which is incredibly useful when you notice
during layout that a figure doesn't look
quite right.
You can go back to your figure-drawing program
(I use Illustrator),
fix the figure,
and then save it in the same place that it
used to be,
over-writing the previous version.
Now InDesign will show a little yellow triangle
on your figure.
Double-click that, and the figure updates to the
new version!
This helps keep all your materials in sync.
When you open the "Place" dialog,
make sure "Replace Selected Item" is not checked.
It will either replace something (as it says)
or it will bring in the image at some default
size,
neither of which I've found to be desirable.
Resist the urge to do anything fancy.
Starting in the middle of the first line
of the caption,
drag out a box for your figure.
If it's going to be full-width, then drag
from one margin to the other.
If it's narrower, just take a guess at
how big it should be.
Unlike other Adobe programs,
do **not** hold down Shift to constrain
the proportions.
When placing a figure,
the Shift key lets you place the
containing object frame with any
size,
and then the content frame is placed
within it as large as possible.
This is rarely useful.
Leaving the Shift key unpressed means
you're placing the object and content
frames simultaneously,
using the aspect ratio of the original figure,
which I've found is a much better
starting place for fine-tuning.
If necessary, choose the "Jump object"
flow icon to get the text to jump over
this graphic
(if you want to use one of the fancier
flow choices, go for it!).
There are two resize boxes for figures.
The light-brown one resizes the contents.
The light-blue one resizes the frame that the
figure sits in.
If the frame is too small, the contents will
be clipped.
If the frame is too big, you'll get extra white
space around the figure,
because the light blue frame is what's used
by the type composer.
I typically play with both sets,
adjusting the brown box until the figure
has a pleasing size.
Then I use the blue box to get enough white
space before and after it.
I'll usually drag the bottom handle down a
little to push the caption down as well,
so the caption doesn't abut directly on
the bottom of the figure.
Also drag the figure left-right and look
for the purple vertical line to show up.
That means you're horizontally centered.
When you see this line,
let go of the mouse.
If the figure and its caption don't have
enough room on the page to stick together,
I move the figure to the top of the next
page and insert a column break
(the enter key on the numerical keypad)
just after the last character in the
paragraph before the figure.
If you're placing multiple figures that
are about the same size, but not full
width, drag a couple of vertical guides
out from the ruler at the left.
That makes it easy to get them all the
same size.
Or you can place one on top of the other,
and smart guides will help you make them
the same size.
Then drag the new figure down to where
it needs to go.
That's it! Move on to the next figure.
Save often.
Summary
=====
1. Write each chapter as a standalone Markdeep file.
1. Edit, edit, edit. Have people read it. Fix all errors. Spell-check. Fix every bug you can find. Really. You want these files to have perfect content, so that layout can focus on layout. Plus, finding errors near the start of a document can force you to have to fix the layout for the whole file, which can take a long time.
1. Create a book document and a style document in InDesign. Sweat the style document until it has all the styles you want, just the way you want them. Spend days on this if you have to. The time will pay itself back quickly.
1. Set the Markdeep option `showLabels` in your first chapter's source file to `False`.
1. Load that chapter in your favorite browser.
1. Select all and copy to the clipboard.
1. Open a blank document in Word, and paste. If you have figures and it prompts you to identify where they are, press Cancel every time. You don't want your figures in your Word doc.
1. Assign character styles in Word for bold and italic to Strong and Emphasis. Assign text set in Courier New to HTML Code style. Note that some Word styles come into InDesign as Character Styles, others Paragraph Styles. These three are Character Styles, which is what we want.
1. Save the Word doc.
1. Set the Markdeep option `showLabels` in your source file to `True`. Refresh the browser.
1. Open your InDesign master style document.
1. Change the master pages to reflect this new chapter. Set headers, footers, splash page, etc. Re-save it immediately as a new file, e.g., "Chapter 1.indd"
1. Add this file to your book
1. Leave the first page blank for the Chapter's TOC.
1. Using InDesign's Place command, select the Word document, then Shift-click to drop it into the master text frame in the first content page in your new file. Give it a moment to create new pages as necessary and flow the text to them.
1. Select all and set all paragraphs to body text style, overriding any paragraph styles (but *not* character styles)
1. In the Character Styles palette, replace styles for bold, italic, and code.
1. Find heads and subheads. Insert numbers, select whole line, and apply paragraph styles while clearing character styles.
1. Change instances of "Figure " to "Figure 5."
1. Set captions for figures and listings. Find `Figure 5.\d+' and set the character style to "Caption Figure Number" and the paragraph style to "Caption".
1. Place figures one by one. Insert column breaks as needed. Adjust the spacing before and after to accommodate the needs of the page and figure.
1. Go to TOC page, click in it, and from the Layout menu either create (or update) the Table of Contents.
1. Save!
1. Repeat for every chapter.
1. Export the book as a PDF.
1. Use Kindle Textbook Generator to convert your PDF to a Kindle file, ready for uploading to the store.