我如何(重新)定义特定于语言的命令(XeTeX,polyglossia)?

我如何(重新)定义特定于语言的命令(XeTeX,polyglossia)?

当我第一次用 pdfTeX 和 babel 编写一个非常大的文档时,我专门为(古)希腊语定义了两个命令:

  1. 在以下位置允许换行\,

    \addto\extrasgreek{%
    \RenewDocumentCommand\,{}{\linebreak[1]\thinspace}}
    
  2. 可以词源化的复合词在连接处有一个细线,首选的单词中断点就在这里。命令是\!(我主要为德语命令复制了它"|):

     \addto\extrasgreek{\let\!\relax%
     \RenewDocumentCommand{\!}{}{\textormath{% \penalty\@M
     \discretionary{-}{}{\kern.01em}%
     \allowhyphens}{}}}
    

\gappto\blockextras@greek{%
  \let\!\relax%
  \NewDocumentCommand{\!}{}{\textormath{% \penalty\@M
      \discretionary{-}{}{\kern.5em}% \kern.01em
      \allowhyphens}{}}}

我明白了

./xetex-greek-commands.tex:77: Argument of \!  has an extra }.
<inserted text> 
                \par 
l.77 ...νατος. τὸ γὰρ ἀει\!κίνητον \ladd{ἀθάνατον}
                                                  . τὸ δ'\,ἄλλο
Runaway argument?
./xetex-greek-commands.tex:77: Paragraph ended before \!  was complete.
<to be read again> 
                   \par 
l.77 ...νατος. τὸ γὰρ ἀει\!κίνητον \ladd{ἀθάνατον}
                                                  . τὸ δ'\,ἄλλο

没有 babel,该命令将不再起作用。我如何才能(重新)定义它们仅用于希腊语部分?如果您对文档进行 TeXify,您将看到被\!用作\negthinspace,之后没有换行符\,

% uses-*- MODE: latex; TeX-engine: xetex -*-
\RequirePackage{scrwfile}
\PreventPackageFromLoading{totpages}
\listfiles
\documentclass[DIV=4]{scrartcl}
\PreventPackageFromLoading{xpatch} % xpatch causes problems with large environments
\PassOptionsToPackage{activate={nocompatibility,true},%
                 expansion=false,final,verbose=silent}{microtype}
\PassOptionsToPackage{no-math}{fontspec}
\usepackage[twothirds,nonegthinspace]{thinsp}
\usepackage{mathtools} % possible conflict with amsmath
\usepackage{unicode-math}
\usepackage{letltxmacro}
\usepackage{xunicode-addon}
\usepackage{polyglossia}
\setmainlanguage[spelling=new,%
                 babelshorthands]{german}
\setotherlanguage[variant=ancient]{greek}
\defaultfontfeatures+[\rmfamily,\sffamily]{Ligatures={TeX,Common}}
\setmainfont{TeXGyrePagellaX}[Extension=.otf,%
                              UprightFont= *-Regular,%
                              BoldFont=*-Bold,%
                              ItalicFont=*-Italic,%
                              BoldItalicFont=*-BoldItalic%
                              ]
\newfontfamily\greekfont{GFS Porson}[Mapping=tex-text,AutoFakeBold,
                                     AutoFakeSlant=.15,%
                                     Scale=MatchUppercase%
                                     ]
\newfontfamily\latinfont{TeXGyrePagellaX}[Extension=.otf,%
                                          UprightFont= *-Regular,%
                                          BoldFont=*-Bold,%
                                          ItalicFont=*-Italic,%
                                          BoldItalicFont=*-BoldItalic
                                          ]
\newfontfamily\greekfontsf{GFSNeohellenic}[Mapping=tex-text,
                                           Extension=.otf,%
                                           UprightFont=*,%
                                           BoldFont=*Bold,%
                                           ItalicFont=*It,%
                                           BoldItalicFont=*BoldIt,%
                                           Scale=MatchUppercase
                                           ]
\usepackage{microtype}
\makeatletter
% from teubner.sty which I can no longer use with XeTeX and polyglossia; here I employ negthinspace 
\DeclareRobustCommand{\Ladd}[1]{{\latinfont\textlangle}%
  {\negthinspace%
    #1\/}{\latinfont\textrangle}}% litterae certe addendae
\DeclareRobustCommand{\ladd}[1]{{\kern.15ex[\negthinspace}%
  {#1\/}{%\metricsfont
    ]\kern-.15ex}} % litterae addendae
\DeclareRobustCommand{\lbrk}{{\latinfont%
    \posthindspace[\negthinspace}}
%-----old definitions----%
\addto\extrasgreek{%
  \RenewDocumentCommand\,{}{\linebreak[1]\thinspace}}
\addto\extrasgreek{\let\!\relax%
  \RenewDocumentCommand{\!}{}{\textormath{% \penalty\@M
      \discretionary{-}{}{\kern.01em}%
      \allowhyphens}{}}}
\addto\extrasgreek{\RenewDocumentCommand{\|}{}{\textbar}}
%------------------------%
\makeatother
\begin{document}
bla bla, some english text

\begin{greek}
  Ψυχὴ πᾶσα ἀθάνατος. τὸ γὰρ ἀει\!κίνητον \ladd{ἀθάνατον}. τὸ δ'\,ἄλλο
  κινοῦν καὶ ὑπ'\,ἄλλου κινούμενον, παῦλαν ἔχον κινήσεως, παῦλαν ἔχει
  ζωῆς. μόνον δὴ τὸ αὑτὸ κινοῦν, ἅτε οὐκ ἀπο\!λεῖπον ἑαυτό, οὔ\!ποτε
  λήγει \Ladd{κινούμενον}, ἀλλὰ καὶ τοῖς ἄλλοις ὅσα κινεῖται τοῦτο
  πηγὴ καὶ ἀρχὴ κινήσεως. ἀρχὴ δὲ ἀγένητον. ἐξ ἀρχῆς γὰρ ἀνάγκη πᾶν τὸ
  γι\!γνόμενον γί\!γνεσθαι, αὐτὴν δὲ μηδ'\,ἐξ ἑνός. εἰ γὰρ ἔκ του ἀρχὴ
  γί\!γνοιτο, οὐκ ἂν ἐξ ἀρχῆς γί\!γνοιτο. ἐπει\!δὴ δὲ ἀγένητόν ἐστιν,
  καὶ ἀδιά\!φθορον αὐτὸ ἀνάγκη εἶναι.
\end{greek}
\end{document}

答案1

结合@gusbrs\gappto\blockextras@greek和@Ulrike Fischer 的方法\let,我终于让它工作了:

% uses-*- MODE: latex; TeX-engine: xetex -*-
\RequirePackage{scrwfile}
\PreventPackageFromLoading{totpages}
\listfiles
\documentclass[DIV=4]{scrartcl}
\PreventPackageFromLoading{xpatch}
\PassOptionsToPackage{activate={nocompatibility,true},%
                 expansion=false,final,verbose=silent}{microtype}
\PassOptionsToPackage{no-math}{fontspec}
\usepackage[twothirds% ,nonegthinspace
]{thinsp}
\usepackage{mathtools} % possible conflict with amsmath
\usepackage{unicode-math}
\usepackage{letltxmacro}
\usepackage{xunicode-addon}
\usepackage{polyglossia}
\setmainlanguage[spelling=new,%
                 babelshorthands]{german}
\setotherlanguage[variant=ancient]{greek}
\defaultfontfeatures+[\rmfamily,\sffamily]{Ligatures={TeX,Common}}
\setmainfont{TeXGyrePagellaX}[Extension=.otf,%
                              UprightFont= *-Regular,%
                              BoldFont=*-Bold,%
                              ItalicFont=*-Italic,%
                              BoldItalicFont=*-BoldItalic%
                              ]
\newfontfamily\greekfont{GFS Porson}[Mapping=tex-text,Language=Greek,AutoFakeBold,
                                     AutoFakeSlant=.15,%
                                     Scale=MatchUppercase%
                                     ]
\newfontfamily\latinfont{TeXGyrePagellaX}[Extension=.otf,%
                                          UprightFont= *-Regular,%
                                          BoldFont=*-Bold,%
                                          ItalicFont=*-Italic,%
                                          BoldItalicFont=*-BoldItalic
                                          ]
\newfontfamily\greekfontsf{GFSNeohellenic}[Mapping=tex-text,Language=Greek,
                                           Extension=.otf,%
                                           UprightFont=*,%
                                           BoldFont=*Bold,%
                                           ItalicFont=*It,%
                                           BoldItalicFont=*BoldIt,%
                                           Scale=MatchUppercase
                                           ]
\usepackage{microtype}
\makeatletter
%-------- from teubner.sty ----------%
\DeclareRobustCommand{\Ladd}[1]{{\latinfont\textlangle}%
  {\negthinspace%
    #1\/}{\latinfont\textrangle}}%
\DeclareRobustCommand{\ladd}[1]{\kern.15ex[\negthinspace%
  #1\/%
    ]\kern-.15ex} %
\DeclareRobustCommand{\lbrk}{{\latinfont%
    \posthindspace[\negthinspace}}
%------------------------------------%
\gappto\blockextras@greek{%
  \let\!\relax
  \def\!{\textormath{% \penalty\@M
      \discretionary{-}{}{\kern.03em}%
      \allowhyphens}{}}
  \LetLtxMacro\|\textbar
  \def\,{\nolinebreak[1]\thinspace}}
\gappto\inlineextras@greek{%
  \let\!\relax
  \def\!{\textormath{% \penalty\@M
      \discretionary{-}{}{\kern.03em}%
      \allowhyphens}{}}
  \LetLtxMacro\|\textbar
  \def\,{\nolinebreak[1]\thinspace}}
%------------------------%
\makeatother
\begin{document}
bla bla, some english text

\enlargethispage{4\baselineskip}
\begin{greek}
  Ψυχὴ πᾶσα ἀθάνατος. τὸ γὰρ ἀει\!κίνητον \ladd{ἀθάνατον}. τὸ δ'\,ἄλλο
  κινοῦν καὶ ὑπ'\,ἄλλου κινούμενον, παῦλαν ἔχον κινήσεως, παῦλαν ἔχει
  ζωῆς. μόνον δὴ τὸ αὑτὸ κινοῦν, ἅτε οὐκ ἀπο\!λεῖπον ἑαυτό, οὔ\!ποτε
  λήγει \Ladd{κινούμενον}, ἀλλὰ καὶ τοῖς ἄλλοις ὅσα κινεῖται τοῦτο
  πηγὴ καὶ ἀρχὴ κινήσεως. ἀρχὴ δὲ ἀγένητον. ἐξ ἀρχῆς γὰρ ἀνάγκη πᾶν τὸ
  γι\!γνόμενον γί\!γνεσθαι, αὐτὴν δὲ μηδ'\,ἐξ ἑνός. εἰ γὰρ ἔκ του ἀρχὴ
  γί\!γνοιτο, οὐκ ἂν ἐξ ἀρχῆς γί\!γνοιτο. ἐπει\!δὴ δὲ ἀγένητόν ἐστιν,
  καὶ ἀδιά\!φθορον αὐτὸ ἀνάγκη εἶναι. \| βλα
\end{greek}
\end{document}

相关内容