朋友们,为什么在环境中使用 \doiftextelse 和 \startsetups(获取章节、节等的名称)时,标题文本前后会出现令人讨厌的空格。但是,当在任何环境之外应用相同的代码时,它就可以正常工作?
梅威瑟:
\startsetups[chapterinfo]
\doiftextelse{\getmarking[chapter]}{\getmarking[chapter]}{\getmarking[chapter]}
\stopsetups
\setupheadertexts[{\setup[chapterinfo]}][][][{\setup[chapterinfo]}]
\showframe
\setuppagenumbering[alternative=doublesided]
\startsectionblockenvironment[frontpart]
\startsetups[chapterinfo]
\doiftextelse{\getmarking[chapter]}{\getmarking[chapter]}{\getmarking[chapter]}
\stopsetups
\setupheadertexts[{\setup[chapterinfo]}][][][{\setup[chapterinfo]}]
\stopsectionblockenvironment
\starttext
\startfrontmatter
\startchapter[title={Chapter}]
\dorecurse{15}
{\input knuth}
\stopchapter
\stopfrontmatter
\startchapter[title={Chapter}]
\dorecurse{15}
{\input knuth}
\stopchapter
\stoptext
答案1
\start...\stopsetups
由于某些原因,在 内使用时不会忽略空格\start...\stopsectionblockenvironment
。如果要在 中使用方括号,\start...\stopsetups
还必须用 隐藏后续空格\startsetups[chapterinfo]%
。
\startsetups chapterinfo
\doiftextelse{\getmarking[chapter]}{\getmarking[chapter]}{\getmarking[chapter]}
\stopsetups
\setupheadertexts[{\setup[chapterinfo]}][][][{\setup[chapterinfo]}]
\showframe
\setuppagenumbering[alternative=doublesided]
\startsectionblockenvironment[frontpart]
\startsetups chapterinfo
\doiftextelse{\getmarking[chapter]}{\getmarking[chapter]}{\getmarking[chapter]}% <-- hide this space
\stopsetups
\setupheadertexts[{\setup[chapterinfo]}][][][{\setup[chapterinfo]}]
\stopsectionblockenvironment
\starttext
\startfrontmatter
\startchapter[title={Chapter}]
\dorecurse{15}{\input knuth}
\stopchapter
\stopfrontmatter
\startchapter[title={Chapter}]
\dorecurse{15}{\input knuth}
\stopchapter
\stoptext
没有%
和%
选择
我不认为这是一个错误,因为设置应该在全局范围内声明。因此,我将全局声明这两个设置,并赋予它们不同的名称,同时揭示它们的使用位置。
\startsetups chapterinfo:main
\doiftextelse{\getmarking[chapter]}{\getmarking[chapter]}{\getmarking[chapter]}
\stopsetups
\startsetups chapterinfo:front
\doiftextelse{\getmarking[chapter]}{\getmarking[chapter]}{\getmarking[chapter]}
\stopsetups
\setupheadertexts[{\setup[chapterinfo:main]}][][][{\setup[chapterinfo:main]}]
\showframe
\setuppagenumbering[alternative=doublesided]
\startsectionblockenvironment[frontpart]
\setupheadertexts[{\setup[chapterinfo:front]}][][][{\setup[chapterinfo:front]}]
\stopsectionblockenvironment
\starttext
\startfrontmatter
\startchapter[title={Chapter}]
\dorecurse{15}{\input knuth}
\stopchapter
\stopfrontmatter
\startchapter[title={Chapter}]
\dorecurse{15}{\input knuth}
\stopchapter
\stoptext