Difference between revisions of "Unexpected behavior"
(follow up of this thread http://archive.contextgarden.net/message/20120611.213208.62aa59bf.en.html) |
(removed paste debris) |
||
Line 1: | Line 1: | ||
+ | |||
If ConTeXt appears to behave in a counterintuitive way, chances are | If ConTeXt appears to behave in a counterintuitive way, chances are | ||
that it’s actually your intuitions that lack calibration. | that it’s actually your intuitions that lack calibration. | ||
Line 307: | Line 308: | ||
What’s the status of this? | What’s the status of this? | ||
--> | --> | ||
− | |||
− | |||
− | |||
− |
Revision as of 13:23, 1 October 2012
If ConTeXt appears to behave in a counterintuitive way, chances are that it’s actually your intuitions that lack calibration.
Contents
Controlling Page Break Before Headings
If you add the option page=yes
to a heading setup, this
will cause ConTeXt to break the page.
Ordinarily this works as expected, unless, however, the heading
immediately follows a previous section with no text in between.
The rationale behind this is that consecutive headings are conceived of
collectively as one single structural element.
For example, the following code will generate only a single page
break although the unit \section appears twice.
\setuphead[section][page=yes] %% toggle page breaking \starttext \chapter{foo} %% structural inhibits breaking \section{bar} \input knuth %% -> no break! \section{baz} \input dawkins %% -> break \stoptext
In order to get the page break at the section regardless of surrounding
structurals elements, you need to unset the heading parameter
continue
as well.
[1]
\setuphead[section][page=yes,continue=no] \starttext \chapter{foo} \section{bar} \input knuth %% -> break \section{baz} \input dawkins %% -> break \stoptext
(For the curious, the explanation can be found in the definition of the macro \\strc_sectioning_handle_page_nop in strc-sec.mkiv).
Unsolicited Vertical Mode
Some commands like \framed cause line breaks to happen if used in vertical mode, e.g. at the beginning of a line. Example:
\starttext \framed{foo} bar. \stoptext
The explanation according to the corresponding
FAQ item
is that before the token \frame
is encountered, TEX is
in vertical mode.
This state is preserved until after TEX finishes typesetting the
\framed
macro.
Consequently, horizontal mode (where paragraphs are made) is entered
only at the tokens bar
.
To have the frame begin the paragraph instead, horizontal mode will
have to be initiated explicitly.
There are a couple macros for this purpose: the very basic
\leavevmode (syst-ini.mkiv; inserts an empty box, same
as in the Plain format) and the more familiar \dontleavehmode
(syst-aux.mkiv).
Just use the immediately before the \framed
macro and
everything should be fine:
\starttext \leavevmode \framed{foo} bar.\par \dontleavehmode \framed{foo} bar. \stoptext
Disappearing Crop Marks
Crop marks, activated as \setuplayout[marking=on]
, are a
useful feature that Context supports out of the box.
They have a peculiarity, though, which my make them useless in specific
cases: They are, by definition, located outside the page dimension.
This means that they show up iff the paper size exceeds the page size.
Thus if you need auxiliary lines for cutting but have the pages fit the paper size exactly, you can instead resort to enabling the page background frame. This example sums up the solutions posted by Wolfgang and Marco on [http://archive.contextgarden.net/message/20120605.202113.0989aa34.en.html the Context Mailing List].
%% the paper size will be a multiple of the page sizes \setuppapersize [A6,landscape] [A3] \setuplayout [nx=2,ny=4]%, marking=on] %% enable the page frame \setupbackgrounds [page] [frame=on] %% some further display setups \setuppagenumbering [location=] \setupbackgrounds [page] [background=color, backgroundcolor=gray] \setupbodyfont [sans,58pt] %% testing ... \starttext \dorecurse{4} {\null\vfill\centerline\recurselevel\vfill\null\page} \stoptext
Left and Right
When it comes to the justification of paragraphs, do not trust your intuitions about handedness. This is a FAQ item.
Footnotes: The Difference between \setupnotation and \setupnote
There is a bit of terminology mess concerning notes.
Instruction | Goal |
---|---|
\setupnotation | This command configures the note insert, i.e. the textual content that will usually be placed at the bottom (with footnotes) or the end of the text (with endnotes). (The control sequence used to be \setupnotedefinition .)
|
\setupnote | Configure the note environment where the inserts will be located. Inherits some parameters from \framed. |
\setupnote[textstyle=,textcommand=]
|
Configure the note symbol as appears in the main text, where the note macro is called. |
Plural forms \setupnotes, \setupnotations | These are synonyms for their singular forms. |
\setupfootnotes | This is equivalent to \setupnote[footnote] .
|
Summary: to setup a blue note, you would first need to define and configure the insert via \setupnotation:
\definenote [bluenote] [footnote] \setupnotation [bluenote] [ color=blue, style=bf, ] \starttext foo\bluenote{bar} baz \stoptext
Now adjust the container where the blue notes will reside at the bottom of the page (\setupnote):
\definenote [bluenote] [footnote] \setupnote [bluenote] [ frame=on, %% frame containing all inserts framecolor=blue, background=screen, rulecolor=blue, %% the line above the inserts rulethickness=1pt, %% both the frame and line width ] \starttext foo\bluenote{bar} baz \bluenote{xyzzy} \stoptext
Finally, direct your attention to the note indicator, most commonly a
number or a symbol.
For precise control over the placement define a monadic macro and hook
it into textcommand
.
\setupnote [bluenote] [ textstyle=\tx\sans\bold\blue, textcommand=\myfootnotecommand, ] \define[1]\myfootnotecommand{\rotate[rotation=42]{#1}} \starttext foo\bluenote{bar} baz \bluenote{xyzzy} \stoptext
(For more definite answers concerning the notes mechanism, use the source, Luke: strc-not.mkvi.)
Float Insertion Issues
Floating objects can be tricky. Deciding where they fit best is hard enough, actually getting them there may be a lot tougher. Inserting a float will force a line break where the object is referenced in the source code. Thus, very long paragraphs may not leave an opportunity to inject the float if they cover the entire page. [2]
\starttext Cows make \placefigure[top]{A genuine Dutch cow.}{\externalfigure[cow]} great pets. \stoptext
In these cases the postponing mechanism offers a reliable way out
(\startpostponing).
It lets you specify an offset (in pages) by which the content of the
postponing environment will be delayed.
In order to place a floating object at the top of the nth page from
the location it is encountered, its argument has needs to be
[+n]
.
(Absolute pages can be specified as simply [n]
.)
E. g. to put the foat on the following page:
\starttext \startpostponing[+1] \placefigure[top]{A genuine Dutch cow.}{\externalfigure[cow.pdf]} \stoppostponing \input knuth \page Cows make great pets. \stoptext
Another solution can be the less known hangaround environment (\starthangaround, cf. Hangaround). It lets the text of a given paragraph (the content of the environment) flow around a box (the first argument). In contrast to real floats it does not place a caption. This poses a problem in MkIV as the new code will not allow placing captions arbitrarily. [[3]] (If you desparately need separate captions please send a feature request to one of the ConTeXt_Mailing_Lists#Mailing Lists).
\starttext \input dawkins \starthangaround{ \framed[align=right,frame=off,width=.3\textwidth]{ \externalfigure [cow] [width=.3\textwidth]\crlf %% NB the fake caption works *only in mkii* \placefloatcaption [figure] [ref:acow] {A smiling Dutch cow. {\italic Bos primigenius taurus}} } } \input dawkins \stophangaround \input dawkins \stoptext
internal error: copy error z1ChF4/cropped.pdf
Syntax
Assignments
In the most common form of key-value type arguments, ConTeXt will accept trailing commas or even empty items. For example, the following code shows this tolerance for the command \definehighlight.
\definehighlight [dontmiss] [ color=red, ,, %% empty option: do nothing style=bold, %% trailing delimiter ]
This is the syntax accepted e.g. by the majority of setups and
\getparameters
.
(For the parser code cf. syst-aux.mkiv.)
There are, however, exceptions to this rule. A known case where
options are processed in a less tolerant fashion is
\setuplabeltext.
[4]
Thus the following snippet will not compile, forcing ConTeXt to fail
with a cryptic Argument of ...
error message.
\setuplabeltext [Nomen=nomen, Est=est, Omen=est,] %% <= fails! \setuplabeltext [Nomen=nomen, Est=est, Omen=omen] %% <= works \starttext \labeltext{Nomen} \labeltext{Est} \labeltext{Omen} \stoptext
(A similar exception concerning \definepalet has been migrated to the standard argument model but may still show the earlier behavior in not so recent installations. [5])