setuphead in connection with the command argument
Hi, I'm trying to adapt the format of chapters in my document and have a few questions regarding setuphead. My aim is to have the chapter (title) on a separate page with an additional intro in different text sizes for title, subtitle and the intro. I chose to use the "command=" argument in setuphead for that. However, I'm not quite sure about it's internals. Let's begin with a minimal example: ``` \define[2]\MyChapter{% #1 #2: \structureuservariable{subtitle} (\structureuservariable{intro}) } \setuphead[title, chapter][command=\MyChapter] \setupbodyfont[11pt] \starttext \startchapter[title=foo][subtitle=bar, intro={some explanation}] some text \stopchapter \stoptext ``` This produces 1.pdf. ## Font size What is the reason that that the font of the chapter is bigger? How can I reset it to normal size? This does not work at all: ``` \define[2]\MyChapter{% \setupbodyfont[11pt] #1 #2: \structureuservariable{subtitle} (\structureuservariable{intro}) } ``` However, changing to a bigger font works somehow. Is there a factor applied to the font size internally? For example: ``` \define[2]\MyChapter{% \setupbodyfont[20pt] #1 #2: \structureuservariable{subtitle} (\structureuservariable{intro}) } ``` produces 2.pdf (the chapter font is not 20pt). ## Line breaks How can I achieve line breaks? This does not work: ``` \define[2]\MyChapter{% #1 #2:\\ \structureuservariable{subtitle}\\ (\structureuservariable{intro}) } ``` (see 3.pdf) I also want to set everything except of the intro in a flushright environment but do not know how. I tried: ``` \define[2]\MyChapter{% \startalignment[flushright] #1 #2:\\ \structureuservariable{subtitle}\\ \stopalignment \structureuservariable{intro} } ``` (see 4.pdf, no change) ## Bold text I tried to get the text bold. However, `#1` and `#2` does not seem to follow this. ``` \define[2]\MyChapter{% \bold #1 #2: \structureuservariable{subtitle} (\structureuservariable{intro}) } ``` ## Makeups The best solution, I had so far, was to define a makeup, but I don't get it to work with text with mixed alignment and it does not solve the font size problem: ``` \definemakeup[chapter][align=left, top=] \define[2]\MyChapter{% \startmakeup[chapter] #1 #2:\\ \structureuservariable{subtitle}\\ \stopmakeup (\structureuservariable{intro}) } ``` (see 5.pdf) ## Framed I also have tried this but it does not bring any linebreaks: ``` \define[2]\MyChapter{% \framed[frame=off, offset=0pt]{#1\\#2:\\ \structureuservariable{subtitle}\\ (\structureuservariable{intro})} } ``` (see 6.pdf) I hope you can shed some light into setuphead with command. I search on the wiki, Stackoverflow and the manuals but didn't really find anything. Best, Gerion
The chapter format that I want to achieve in the end is nearly the one in the attachment (excerpt of Christian Dietrich's PhD thesis). Best Gerion Am Donnerstag, 30. Mai 2024, 16:15:01 MESZ schrieb Gerion Entrup:
Hi,
I'm trying to adapt the format of chapters in my document and have a few questions regarding setuphead. My aim is to have the chapter (title) on a separate page with an additional intro in different text sizes for title, subtitle and the intro. I chose to use the "command=" argument in setuphead for that. However, I'm not quite sure about it's internals.
Let's begin with a minimal example: ``` \define[2]\MyChapter{% #1 #2: \structureuservariable{subtitle} (\structureuservariable{intro}) }
\setuphead[title, chapter][command=\MyChapter]
\setupbodyfont[11pt]
\starttext \startchapter[title=foo][subtitle=bar, intro={some explanation}] some text \stopchapter \stoptext ``` This produces 1.pdf.
## Font size
What is the reason that that the font of the chapter is bigger? How can I reset it to normal size? This does not work at all: ``` \define[2]\MyChapter{% \setupbodyfont[11pt] #1 #2: \structureuservariable{subtitle} (\structureuservariable{intro}) } ``` However, changing to a bigger font works somehow. Is there a factor applied to the font size internally? For example: ``` \define[2]\MyChapter{% \setupbodyfont[20pt] #1 #2: \structureuservariable{subtitle} (\structureuservariable{intro}) } ``` produces 2.pdf (the chapter font is not 20pt).
## Line breaks
How can I achieve line breaks? This does not work: ``` \define[2]\MyChapter{% #1 #2:\\ \structureuservariable{subtitle}\\ (\structureuservariable{intro}) } ``` (see 3.pdf)
I also want to set everything except of the intro in a flushright environment but do not know how. I tried: ``` \define[2]\MyChapter{% \startalignment[flushright] #1 #2:\\ \structureuservariable{subtitle}\\ \stopalignment \structureuservariable{intro} } ``` (see 4.pdf, no change)
## Bold text
I tried to get the text bold. However, `#1` and `#2` does not seem to follow this. ``` \define[2]\MyChapter{% \bold #1 #2: \structureuservariable{subtitle} (\structureuservariable{intro}) } ```
## Makeups
The best solution, I had so far, was to define a makeup, but I don't get it to work with text with mixed alignment and it does not solve the font size problem: ``` \definemakeup[chapter][align=left, top=] \define[2]\MyChapter{% \startmakeup[chapter] #1 #2:\\ \structureuservariable{subtitle}\\ \stopmakeup (\structureuservariable{intro}) } ``` (see 5.pdf)
## Framed
I also have tried this but it does not bring any linebreaks: ``` \define[2]\MyChapter{% \framed[frame=off, offset=0pt]{#1\\#2:\\ \structureuservariable{subtitle}\\ (\structureuservariable{intro})} } ``` (see 6.pdf)
I hope you can shed some light into setuphead with command. I search on the wiki, Stackoverflow and the manuals but didn't really find anything.
Best, Gerion
Gerion Entrup schrieb am 30.05.2024 um 16:25:
The chapter format that I want to achieve in the end is nearly the one in the attachment (excerpt of Christian Dietrich's PhD thesis).
When you have a complex layout it is easier to use the \defineheadalternative command to create it. To change the font for each element disable the default settings with \setuphead[style=] and use \startfont (or \definedfont) to apply a different style for the number, title etc. %%%% begin example \defineframed [ChapterFrame] [width=\textwidth, align=flushright, offset=0pt, rulethickness=0pt] \startsetups [christian_dietrich] \startlocalheadsetup \startframed[ChapterFrame] \blank[2cm] \startfont[Serif sa 8] \color[darkgray]{\headnumbercontent} \stopfont \blank[5mm] \startfont[SerifBold sa 2] \color[darkred]{\headtextcontent} \stopfont \blank[1cm] \startfont[SerifBold sa 1.5] \color[darkred]{\structureuservariable{subtitle}} \stopfont \stopframed \stoplocalheadsetup \stopsetups \defineheadalternative [christian_dietrich] [renderingsetup=christian_dietrich] \setuphead [chapter] [alternative=christian_dietrich, header=empty, style=] \starttext \startchapter[title=Chapter title][subtitle=Chapter subtitle] \samplefile{lorem} \stopchapter \stoptext %%%% end example Wolfgang
Am Donnerstag, 30. Mai 2024, 22:54:47 MESZ schrieb Wolfgang Schuster:
Gerion Entrup schrieb am 30.05.2024 um 16:25:
The chapter format that I want to achieve in the end is nearly the one in the attachment (excerpt of Christian Dietrich's PhD thesis).
When you have a complex layout it is easier to use the \defineheadalternative command to create it.
To change the font for each element disable the default settings with \setuphead[style=] and use \startfont (or \definedfont) to apply a different style for the number, title etc.
%%%% begin example \defineframed [ChapterFrame] [width=\textwidth, align=flushright, offset=0pt, rulethickness=0pt]
\startsetups [christian_dietrich] \startlocalheadsetup \startframed[ChapterFrame] \blank[2cm] \startfont[Serif sa 8] \color[darkgray]{\headnumbercontent} \stopfont \blank[5mm] \startfont[SerifBold sa 2] \color[darkred]{\headtextcontent} \stopfont \blank[1cm] \startfont[SerifBold sa 1.5] \color[darkred]{\structureuservariable{subtitle}} \stopfont \stopframed \stoplocalheadsetup \stopsetups
\defineheadalternative [christian_dietrich] [renderingsetup=christian_dietrich]
\setuphead [chapter] [alternative=christian_dietrich, header=empty, style=]
\starttext
\startchapter[title=Chapter title][subtitle=Chapter subtitle] \samplefile{lorem} \stopchapter
\stoptext %%%% end example
Thank you very much! That looks really clean. I will add it to the wiki. Can you bring some clarification regarding "style=", "command=" and "alternative="? What, if I define multiple of them? Is the system not made for this? I just tested my initial example regarding font size with `command=\MyChapter, style=` and the font size was only affected by the code of \MyChapter. What is the default style? Best Gerion
Gerion Entrup schrieb am 31.05.2024 um 00:37:
Am Donnerstag, 30. Mai 2024, 22:54:47 MESZ schrieb Wolfgang Schuster:
Gerion Entrup schrieb am 30.05.2024 um 16:25:
The chapter format that I want to achieve in the end is nearly the one in the attachment (excerpt of Christian Dietrich's PhD thesis).
When you have a complex layout it is easier to use the \defineheadalternative command to create it.
To change the font for each element disable the default settings with \setuphead[style=] and use \startfont (or \definedfont) to apply a different style for the number, title etc.
%%%% begin example [...] %%%% end example
Thank you very much! That looks really clean. I will add it to the wiki.
Can you bring some clarification regarding "style=", "command=" and "alternative="?
1. Alternatives are the different styles/layouts for the section titles. The example below demonstrates a few of them and you can create your own styles with \defineheadalternative. The command key provides a different method to create your own style/layout and in most cases it doesn't mattter which method you use, only when you want an inline title like "alternative=text" you need \defineheadalternative because it allows you to set a few flags which are needed here. The biggest difference between both is that command uses arguments to place the number (#1) and title (#2) while headalternative use the two macros \headnumbercontent and \headtextcontent. %%%% begin example \starttext % \setuphead[section][alternative=normal] % default alternative \section{Lorem ipsum} \samplefile{lorem} \page \setuphead[section][alternative=text] \section{Lorem ipsum} \samplefile{lorem} \page \setuphead[section][alternative=middle] \section{Lorem ipsum} \samplefile{lorem} \page \setuphead[section][alternative=margin] \section{Lorem ipsum} \samplefile{lorem} \stoptext %%%% end example 2. The "style" key is used to set a custom font/style for all elements of the section, when you set an empty value the title uses the current style of the document. You can also apply different styles to the number and title with the two key "numberstyle" and "titlestyle", the resulting effect is a combination of the general "style" value and the special "numberstyle" or "titlestyle" value. Below are few examples where I use a few combinations of the general and special settings. %%%% begin example \starttext \section{Lorem ipsum} \samplefile{lorem} \page \setuphead[section][style=\bfc] \section{Lorem ipsum} \samplefile{lorem} \page \setuphead[section][style=\tfa,textstyle=\bf,numberstyle={\feature[+][oldstyle]}] \section{Lorem ipsum} \samplefile{lorem} \page \setuphead[section][style={\switchtobodyfont[heros]\tfa},textstyle=,numberstyle=] \section{Lorem ipsum} \samplefile{lorem} \stoptext %%%% end example
What, if I define multiple of them? Is the system not made for this?
Multiple of what?
I just tested my initial example regarding font size with `command=\MyChapter, style=` and the font size was only affected by the code of \MyChapter. What is the default style?
The default style is whatever you set with \setupbofyfont at the begin of the document. To get the default settings for \chapter etc. you can use the \showinstancevalues which creates a table which prints the values. %%%% begin example \usemodule[setups] \starttext \showinstancevalues[head][chapter] \showrootvalues[head] \stoptext %%%% end example Wolfgang
Am Samstag, 1. Juni 2024, 09:53:46 MESZ schrieb Wolfgang Schuster:
Gerion Entrup schrieb am 31.05.2024 um 00:37:
What, if I define multiple of them? Is the system not made for this?
Multiple of what?
When I define `alternative=` _and_ `command=` in the same `\setuphead`. Or `alternative=` and `style=`, or `alternative=` and `command=`. I guess style is applied just to the arguments/macros of the command/the alternative? And combining alternative and command never make sense. Thank you very much for your long answer, that was very enlightening! Best Gerion
Gerion Entrup schrieb am 01.06.2024 um 16:34:
Am Samstag, 1. Juni 2024, 09:53:46 MESZ schrieb Wolfgang Schuster:
Gerion Entrup schrieb am 31.05.2024 um 00:37:
What, if I define multiple of them? Is the system not made for this?
Multiple of what?
When I define `alternative=` _and_ `command=` in the same `\setuphead`. Or `alternative=` and `style=`, or `alternative=` and `command=`.
I guess style is applied just to the arguments/macros of the command/the alternative? And combining alternative and command never make sense.
The following descriptions applies to most setup commands when exclude special cases like \setupbodyfont or \setuplayout. When you make multiple changes to the values of a command with \setuphead [section] [style=bold] and \setuphead [section] [color=blue] you achieve the same result as setting both values at the same time like \setuphead [section] [style=bold,color=blue] What you're doing here is just passing some value to a parameter, nothing else happens at this time. When you process a document Context has already passed the value "normal" to the "alternative" parameter in the \setuphead command. When you now pass a custom macro the "command" parameter in \setuphead all you have done is to set a value, nothing else happened at this point. The evaluation of the parameter happens when Context places the content of a heading with \startchapter etc. in your document and only at this point it has to make a decision what should happen when both "command" and "alternative" are set. The order in which the parameters are used is the following: a) check if the "command" parameter has a value and if this is true is it and ignore the "alternative" value b) if no value is present for the "command" parameter use the value of "alternative". The value of the "style" parameter is unrelated of the command/alternative values because it isn't needed to choose a layout for the heading, all the parameter does is to change the font/style which is independent of the layout. Wolfgang
Am Montag, 3. Juni 2024, 00:05:22 MESZ schrieb Wolfgang Schuster:
Gerion Entrup schrieb am 01.06.2024 um 16:34:
Am Samstag, 1. Juni 2024, 09:53:46 MESZ schrieb Wolfgang Schuster:
Gerion Entrup schrieb am 31.05.2024 um 00:37:
What, if I define multiple of them? Is the system not made for this?
Multiple of what?
When I define `alternative=` _and_ `command=` in the same `\setuphead`. Or `alternative=` and `style=`, or `alternative=` and `command=`.
I guess style is applied just to the arguments/macros of the command/the alternative? And combining alternative and command never make sense.
The following descriptions applies to most setup commands when exclude special cases like \setupbodyfont or \setuplayout.
When you make multiple changes to the values of a command with
\setuphead [section] [style=bold]
and
\setuphead [section] [color=blue]
you achieve the same result as setting both values at the same time like
\setuphead [section] [style=bold,color=blue]
What you're doing here is just passing some value to a parameter, nothing else happens at this time. When you process a document Context has already passed the value "normal" to the "alternative" parameter in the \setuphead command. When you now pass a custom macro the "command" parameter in \setuphead all you have done is to set a value, nothing else happened at this point.
The evaluation of the parameter happens when Context places the content of a heading with \startchapter etc. in your document and only at this point it has to make a decision what should happen when both "command" and "alternative" are set. The order in which the parameters are used is the following: a) check if the "command" parameter has a value and if this is true is it and ignore the "alternative" value b) if no value is present for the "command" parameter use the value of "alternative".
The value of the "style" parameter is unrelated of the command/alternative values because it isn't needed to choose a layout for the heading, all the parameter does is to change the font/style which is independent of the layout.
Thank you. I think that I understand command vs alternative now. With try and error, I experienced, that the font/style of the `style` parameter interleave in a strange way. Therefore I see it as related. What i mean is: Example 1 ``` \define[2]\MyChapter{% \bold This is bold #1 #2 } \setuphead[title, chapter][command=\MyChapter, style=\italic] \starttext \startchapter[title=foo] \stopchapter \stoptext ``` "This is bold" is bold, but "1" and "foo" are italic. The font size is normal. It seems, that "style" is just applied to "#1" and "#2" _before_ evaluating MyChapter. Example 2 ``` \define[2]\MyChapter{% \bold This is bold #1 #2 } % this should be the "default" style \setuphead[title, chapter][command=\MyChapter, style=\tfc] \starttext \startchapter[title=foo] \stopchapter \stoptext ``` "This is bold" is bold, "1" and "2" are normal, but the whole font size is bigger. It seems, that "style" is applied partially to the whole text and somehow special to "#1" and "#2" (Why are these arguments not bold?) As of your explanations, I currently think of the following logic for typesetting (in pseudocode): ``` function typeset_chapter(style, numberstyle, textstyle, command, alternative, chapter_number, chapter_title) { local formatted_chapter_number = apply_style(numberstyle, apply_style(style, chapter_number)) local formatted_chapter_title = apply_style(textstyle, apply_style(style, chapter_title)) if (alternative != "normal") set_TeX_macro("\headnumbercontent", formatted_chapter_number) set_TeX_macro("\headtextcontent", formatted_chapter_title) typeset_as_TeX(get_TeX_code(alternative)) else evaluate_TeX_function(command, #1=formatted_chapter_number, #2=formatted_chapter_title) endif } ``` But this does not fit to example 2. Best Gerion
Thank you. I think that I understand command vs alternative now. With try and error, I experienced, that the font/style of the `style` parameter interleave in a strange way. Therefore I see it as related. What i mean is:
On 6/3/2024 1:36 PM, Gerion Entrup wrote: style: outer level, also sets interline spacing and adapts before after blanks numberstyle and textstyle : specific to the element Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
Am Montag, 3. Juni 2024, 15:13:20 MESZ schrieb Hans Hagen via ntg-context:
Thank you. I think that I understand command vs alternative now. With try and error, I experienced, that the font/style of the `style` parameter interleave in a strange way. Therefore I see it as related. What i mean is:
On 6/3/2024 1:36 PM, Gerion Entrup wrote: style: outer level, also sets interline spacing and adapts before after blanks
numberstyle and textstyle : specific to the element
Thank you! I will try to wrap it up in the Wiki. Gerion
On 30 May 2024, at 15:15, Gerion Entrup
wrote: Let's begin with a minimal example: ``` \define[2]\MyChapter{% #1 #2: \structureuservariable{subtitle} (\structureuservariable{intro}) }
Stop there! Use \definehead to create your own variation of a heading - much more robust. Something like the following (untested): \startsetups PlaceSubTitleAndIntro % Set font and and style etc for the subtitle here \structureuservariable(subtitle) % Set font and style etc for the intro text here \structureuservariable(intro) \stopsetups \definehead [MyChapter] [chapter] \setuphead [MyChapter] [ style={...}, % heading style after={\setup{PlaceSubTitleAndIntro}}, ] \starttext \startMyChapter[title={Foo}] [ subtitle={Bar}, intro={Some explanation}, ] The text of the chapter \stopMyChapter \stoptext — Bruce Horrocks Hampshire, UK
Am Donnerstag, 30. Mai 2024, 18:49:08 MESZ schrieb Bruce Horrocks:
On 30 May 2024, at 15:15, Gerion Entrup
wrote: Let's begin with a minimal example: ``` \define[2]\MyChapter{% #1 #2: \structureuservariable{subtitle} (\structureuservariable{intro}) }
Stop there!
Use \definehead to create your own variation of a heading - much more robust. Something like the following (untested):
\startsetups PlaceSubTitleAndIntro % Set font and and style etc for the subtitle here \structureuservariable(subtitle)
% Set font and style etc for the intro text here \structureuservariable(intro) \stopsetups
\definehead [MyChapter] [chapter] \setuphead [MyChapter] [ style={...}, % heading style after={\setup{PlaceSubTitleAndIntro}}, ]
\starttext \startMyChapter[title={Foo}] [ subtitle={Bar}, intro={Some explanation}, ] The text of the chapter \stopMyChapter \stoptext
Thanks for the input. A comparable example is also listed in the wiki. I like the approach for placing subtitle and intro alone. However, I also want to style chapter number and chapter title separately. I'm also not sure, if an extra heading (MyChapter) is needed, since all my chapters are styled in this way. Isn't it possible to define "after" of chapter directly? Best Gerion
On 30 May 2024, at 23:25, Gerion Entrup
wrote: Am Donnerstag, 30. Mai 2024, 18:49:08 MESZ schrieb Bruce Horrocks:
On 30 May 2024, at 15:15, Gerion Entrup
wrote: Let's begin with a minimal example: ``` \define[2]\MyChapter{% #1 #2: \structureuservariable{subtitle} (\structureuservariable{intro}) }
Stop there!
Use \definehead to create your own variation of a heading - much more robust. Something like the following (untested):
\startsetups PlaceSubTitleAndIntro % Set font and and style etc for the subtitle here \structureuservariable(subtitle)
% Set font and style etc for the intro text here \structureuservariable(intro) \stopsetups
\definehead [MyChapter] [chapter] \setuphead [MyChapter] [ style={...}, % heading style after={\setup{PlaceSubTitleAndIntro}}, ]
\starttext \startMyChapter[title={Foo}] [ subtitle={Bar}, intro={Some explanation}, ] The text of the chapter \stopMyChapter \stoptext
Thanks for the input. A comparable example is also listed in the wiki. I like the approach for placing subtitle and intro alone. However, I also want to style chapter number and chapter title separately.
Any setuphead commands that apply to MyChapter also apply to chapter so you should be able to use exactly the same styling commands.
I'm also not sure, if an extra heading (MyChapter) is needed, since all my chapters are styled in this way. Isn't it possible to define "after" of chapter directly?
Yes, I think it is possible to just use \setuphead [chapter] instead of \setuphead [MyChapter] with the rest remaining the same. The only reason I don't do it is that if something goes wrong, I know I have an original version of \chapter readily to hand to compare against for debugging. Regards, — Bruce Horrocks Hampshire, UK
participants (4)
-
Bruce Horrocks
-
Gerion Entrup
-
Hans Hagen
-
Wolfgang Schuster