
I've been writing bilingual documentation lately. When I switched the font class, I found that it was back to the default size. How should I just switch the font class without changing the font size or other attributes. %%%%%% \starttext \section{A\textbar A} \section{A\textbar{\switchtobodyfont[pagella]A}}% fontsize changed to default fontsize {\tfa A}\textbar{\tfa \switchtobodyfont[pagella]A}\textbar{A}% not work {\tfa A}\textbar{\switchtobodyfont[pagella]\tfa A}\textbar{A} % work but not handy \stoptext %%%%%% more about this issue, I don't know if context contains a command to switch fonts with the language. %%%%%% not work \starttext \appendtoks \usebodyfontparameter\languageparameter \languageparameter{bodyfont} \to \everylanguage \setuplanguage[cn][bodyfont={pagella,12pt}] A \the\font \textbar \cn A \the\font \stoptext %%%%%% thank for your help, autumnus

Am 22.02.2025 um 11:59 schrieb autumnus:
I've been writing bilingual documentation lately. When I switched the font class, I found that it was back to the default size. How should I just switch the font class without changing the font size or other attributes.
%%%%%% \starttext \section{A\textbar A}
\section{A\textbar{\switchtobodyfont[pagella]A}}% fontsize changed to default fontsize
{\tfa A}\textbar{\tfa \switchtobodyfont[pagella]A}\textbar{A}% not work
{\tfa A}\textbar{\switchtobodyfont[pagella]\tfa A}\textbar{A} % work but not handy \stoptext %%%%%%
1. Preload all typescripts at the start of the document. \usebodyfont[pagella] \setupbodyfont[modern] 2. Set a fixed size for the heading. \setuphead[section][style={\switchtobodyfont[14.4pt]}] 3. Use the fallback mechanism for fonts.
more about this issue, I don't know if context contains a command to switch fonts with the language.
%%%%%% not work \starttext \appendtoks \usebodyfontparameter\languageparameter \languageparameter{bodyfont} \to \everylanguage
\setuplanguage[cn][bodyfont={pagella,12pt}]
A \the\font \textbar \cn A \the\font
\stoptext %%%%%%
You can use the setups mechanism. \startsetups [language:cn] \switchtobodyfont[pagella] \stopsetups \setuplanguage[cn][setups=language:cn] Wolfgang

Thanks for the solution. Using absolute values in headings can solve the problem of font size changes when font switches. But in the text, it still exists. I found a [\switchstyleonly] in the source file via the [\usebodyfont] you mentioned. So, why don't we have a [\switchclassonly]. Maybe I'm not right? I'm currently using a cumbersome way to define a new command. But I'm not sure if this will cause some side effects that I don't know about. %%%%% tolerantdefswitchonlyclass[#1]% {edefprevstyle{fontstyle}% scratchcounterglyphscale switchtobodyfont[#1]% glyphscalescratchcounter} %%%%% Font fallback does solve part of the problem. But when this bilingual document is in Chinese and Japanese, there's nothing the font fallback can do. Because they all use almost the same Hanzi characters, but differ in glyphs, we have to switch between different fonts. Maybe we can extend the functionality of language. For example, when switching languages, switch the script, switch the font, switch the indentation, switch the line spacing, and switch the paragraph spacing. This can be helpful for bilingual documentation.

Am 24.02.2025 um 04:22 schrieb autumnus:
Thanks for the solution.
Using absolute values in headings can solve the problem of font size changes when font switches. But in the text, it still exists.
It took another look at the problem and noticed it happens only with the new compact mode for fonts which is now active by default (to use the old font mode use "context --nocompactfonts <filename>"). Below is a patch for compact mode (I guess \font_scale_defined_x and \font_scale_defined_xx have to be patched too) but Hans has to take a look at it. \unprotect \def\font_scale_defined {\glyphscale\dimexpr\f_font_rscale_used\dimexpr\textface*\plushundred/\onepoint\relax\relax %% begin patch \ifempty\fontclass \applyfontstrategies \else \applyfontclassstrategies \fi %% end patch \ifskipfontcharacteristics \else \expand\everyfont % \setfontcharacteristics \expand\everyfontswitch \fi} \protect \usebodyfont[pagella] \setupbodyfont[modern] \starttext {\tfd Latin Modern \switchtobodyfont[pagella]TeX Gyre Pagella} {\tfd Latin Modern \setupbodyfont[pagella]TeX Gyre Pagella} \stoptext Wolfgang

sorry, I forgot to translate and sent it directly in Chinese. Thank you, this really solves the problem.

Am 24.02.2025 um 04:22 schrieb autumnus:
Thanks for the solution.
[...]
Maybe we can extend the functionality of language. For example, when switching languages, switch the script, switch the font, switch the indentation, switch the line spacing, and switch the paragraph spacing. This can be helpful for bilingual documentation.
In my opinion you should create an environment (e.g. \definestartstop[chinese]) which sets the apprpriate values for linespacing etc. The language switch isn't the proper hook for this because you prbably need it in the middle of a paragraph to change the lanuage for a single word etc. Another solution is to use the paragraph environment and create named paragraphs for each language, this can also be done with extreme tables and named table cells (e.g. \startxcell[chinese]). Wolfgang

I designed a new command. But I found a problem. We have the command [\useinterlinespaceparameter], I thought it would work like \usealignparameter or \usebodyfontparameter, But in the actual testing process, the command does not seem to work at all. % Therefore, I used \dosetupcheckedinterlinespace. In addition, I found that there is also [\useinterlinespaceparameter] in the footnote. it also can't work. Although we can make additional settings through \setups. Or maybe is there something wrong with [\useinterlinespaceparameter]? %%%%%% \unprotect \let\sys_language\language \installnamespace {userlanguage} \installcommandhandler \????userlanguage {userlanguage} \????userlanguage \setupuserlanguage[en][ % interlinespace=, indenting=,] \setupuserlanguage[cn][ % interlinespace=, indenting={yes,2em},] \tolerant\protected\def\userlanguage#*[#1]#*[#2]#*% {\edef\currentuserlanguage{#1}% \ifarguments\or\or \setuplanguage[#1][#2]% \setupuserlanguage[#1][#2]\fi \sys_language[#1]% \ifhmode\else\par \edef\p_language_interlinespace{\userlanguageparameter\c!interlinespace}% \useindentingparameter\userlanguageparameter % \useinterlinespaceparameter\userlanguageparameter% not work \dosetupcheckedinterlinespace\p_language_interlinespace% work \fi \lettonothing\currentuserlanguage} \protect \starttext {\userlanguage[cn]How about \CONTEXT's apostrophes? {\userlanguage[en]How about \CONTEXT's apostrophes?}} {\userlanguage[cn][interlinespace=42pt]\ss\input knuthmath \par} {\userlanguage[en][interlinespace=22pt]\tt\input knuthmath \par} \input knuthmath \stoptext %%%%%%

Am 26.02.2025 um 13:20 schrieb autumnus:
I designed a new command. But I found a problem.
We have the command [\useinterlinespaceparameter], I thought it would work like \usealignparameter or \usebodyfontparameter, But in the actual testing process, the command does not seem to work at all. % Therefore, I used \dosetupcheckedinterlinespace.
In addition, I found that there is also [\useinterlinespaceparameter] in the footnote. it also can't work. Although we can make additional settings through \setups. Or maybe is there something wrong with [\useinterlinespaceparameter]?
[...]
\tolerant\protected\def\userlanguage#*[#1]#*[#2]#*% {...}
You don't need #* before the first and after the last argument, only between the optional (or mandatory) argument to permit spaces. The \useinterlinespaceparameter command works when you pass a named interlinespace instance, which is created with \defineinterlinespace. \unprotect \installnamespace {userlanguage} \installcommandhandler \????userlanguage {userlanguage} \????userlanguage \protect \setupuserlanguage [en] [interlinespace=english] \setupuserlanguage [cn] [interlinespace=chinese] \defineinterlinespace [english] [line=2.4ex] \defineinterlinespace [chinese] [line=4.0ex] \starttext \samplefile{lorem} \cdef\currentuserlanguage{en} \useinterlinespaceparameter\userlanguageparameter \samplefile{lorem} \cdef\currentuserlanguage{cn} \useinterlinespaceparameter\userlanguageparameter \samplefile{lorem} \stoptext Wolfgang
participants (2)
-
autumnus
-
Wolfgang Schuster