babel 包和子图的问题

babel 包和子图的问题

我尝试通过在序言中添加以下内容来改变文章的语言:

\usepackage[greek,english]{babel}
\selectlanguage{greek}

在大多数情况下似乎工作正常。但是当我在子图中添加标题时,出现以下错误:

l.308       \caption{*somecaption* }
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

LaTeX Info: Redefining \anw@print on input line 308.
LaTeX Info: Redefining \anw@print on input line 308.
LaTeX Info: Redefining \anw@print on input line 308.
LaTeX Info: Redefining \anw@print on input line 308.
File: *somepath* Graphic file (type QTm)
<use  "*somepath*" >
./Section5_Results.tex:313: Undefined control sequence.
 \greeknumeral #1->\let \@numer@lsign 
                                 \numer@lsign \let \numer@lsign   \anwtono...

代码示例:

 \begin{figure}[H]
\centering
\begin{subfigure}[b]{0.4\textwidth}
  \includegraphics[width=\textwidth]{*somepath*}
  \caption{*somecaption*}
\end{subfigure}
~
\begin{subfigure}[b]{0.4\textwidth}
  \includegraphics[width=\textwidth]{*somepath*}
  \caption{*somecaption*} 
\end{subfigure}
\caption{*somecaption*}
\end{figure}

编辑1

我创建了一个代码示例来重现该问题,但没有成功。此外,我注意到我应该将\selectlanguage{greek}从前言移到“主体”(紧接着\begin{document})。之后,我在两个文档中都遇到了相同的以下错误:

./latex_example.tex:33: LaTeX Error: Command \nobreakspace unavailable in    encoding LGR.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
...                                              

l.33 ... είναι μια επικεφαλίδα}

示例代码:

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[greek,english]{babel}
\usepackage[LGR,T1]{fontenc}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{xgreek}
\usepackage{float}
\usepackage{graphicx}
\usepackage[cm-default]{fontspec}


\begin{document}
\selectlanguage{greek}
% \selectlanguage{english} %This works nicely

\today

\begin{figure}[H]
  \centering
  \begin{subfigure}[b]{0.4\textwidth}
    \includegraphics[width=\textwidth]{maxresdefault.jpg}
    \subcaption{Αυτό είναι μια υπο-επικεφαλίδα}
    % \subcaption{This works nicely}
  \end{subfigure}
  ~
  \begin{subfigure}[b]{0.4\textwidth}
    \includegraphics[width=\textwidth]{maxresdefault.jpg}
    \subcaption{Αυτό είναι μια υπο-επικεφαλίδα}
    % \subcaption{This works nicely}
  \end{subfigure}
  \caption{Αυτό είναι μια επικεφαλίδα}
  % \caption{This works nicely}
\end{figure}

\end{document}

编辑2

@egreg 建议我更新 TeX 并将其替换\usepackage{fontenc}\usepackage{fontspec}我跟着本指南以便更新 TeX 版本。我使用了与 @egreg 完全相同的代码,现在我得到了一个完全不同的错误,这是整个日志文件:

>xelatex latex_example.tex 
      This is XeTeX, Version 3.14159265-2.6-0.99999 (TeX Live 2018) (preloaded format=xelatex)
 restricted \write18 enabled.
entering extended mode
(./latex_example.tex
LaTeX2e <2018-04-01> patch level 5
(/usr/local/texlive/2018/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/local/texlive/2018/texmf-dist/tex/latex/base/size10.clo))
(/usr/local/texlive/2018/texmf-dist/tex/generic/babel/babel.sty
(/usr/local/texlive/2018/texmf-dist/tex/generic/babel/switch.def)
(/usr/local/texlive/2018/texmf-dist/tex/generic/babel-english/english.ldf
(/usr/local/texlive/2018/texmf-dist/tex/generic/babel/babel.def
(/usr/local/texlive/2018/texmf-dist/tex/generic/babel/xebabel.def
(/usr/local/texlive/2018/texmf-dist/tex/generic/babel/txtbabel.def))))
(/usr/local/texlive/2018/texmf-dist/tex/generic/babel-greek/greek.ldf
(/usr/local/texlive/2018/texmf-dist/tex/latex/greek-fontenc/lgrenc.def
(/usr/local/texlive/2018/texmf-dist/tex/latex/greek-fontenc/greek-fontenc.def))
)) (/usr/local/texlive/2018/texmf-dist/tex/latex/base/inputenc.sty

Package inputenc Warning: inputenc package ignored with utf8 based engines.

) (/home/manos/texmf/tex/latex/fontspec/fontspec.sty
(/usr/local/texlive/2018/texmf-dist/tex/latex/l3kernel/expl3.sty
(/usr/local/texlive/2018/texmf-dist/tex/latex/l3kernel/expl3-code.tex)
(/usr/local/texlive/2018/texmf-dist/tex/latex/l3kernel/l3xdvipdfmx.def))
(/usr/local/texlive/2018/texmf-dist/tex/latex/l3packages/xparse/xparse.sty)
(/home/manos/texmf/tex/latex/fontspec/fontspec-xetex.sty
*************************************************
* fontspec warning: "cm-default-obsolete"
* 
* The "cm-default" package option is obsolete.
*************************************************
(/usr/local/texlive/2018/texmf-dist/tex/latex/base/fontenc.sty
(/usr/local/texlive/2018/texmf-dist/tex/latex/euenc/eu1enc.def)
(/usr/local/texlive/2018/texmf-dist/tex/latex/euenc/eu1lmr.fd))
(/home/manos/texmf/tex/xelatex/xunicode/xunicode.sty
*** you should *not* be loading the inputenc package
*** XeTeX expects the source to be in UTF8 encoding
*** some features of other encodings may conflict, resulting in poor output.
(/usr/local/texlive/2018/texmf-dist/tex/latex/tipa/t3enc.def
(/usr/local/texlive/2018/texmf-dist/tex/latex/euenc/eu1lmss.fd))
(/usr/local/texlive/2018/texmf-dist/tex/latex/graphics/graphicx.sty
(/usr/local/texlive/2018/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/local/texlive/2018/texmf-dist/tex/latex/graphics/graphics.sty
(/usr/local/texlive/2018/texmf-dist/tex/latex/graphics/trig.sty)
(/usr/local/texlive/2018/texmf-dist/tex/latex/graphics-cfg/graphics.cfg)
(/usr/local/texlive/2018/texmf-dist/tex/latex/graphics-def/xetex.def))))
Runaway argument?
{\dim_set:Nn ##1{\fontdimen ##2##3}\dim_compare:nNnT ##1={0pt}{\settoheight \ET
C.
! Forbidden control sequence found while scanning use of \__cs_generate_from_si
gnature:nnNNNn.
<inserted text> 
                \par 
l.1767       \int_case:nnn
                           #2
? 
! Undefined control sequence.
<argument> \LaTeX3 error: 
                           The deprecated command '\int_case:nnn' has been o...
l.1767       \int_case:nnn
                           #2
? 

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! LaTeX error: "kernel/deprecated-command"
! 
! The deprecated command '\int_case:nnn' has been or will be removed on
! 2015-07-14. Use instead '\int_case:nnF '.
! 
! See the LaTeX3 documentation for further information.
! 
! Type <return> to continue.
!...............................................  

l.1767       \int_case:nnn
                           #2
? 
! You can't use `macro parameter character #' in vertical mode.
l.1767       \int_case:nnn #
                            2
? 

! LaTeX Error: Missing \begin{document}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.1767       \int_case:nnn #2

? 
! Too many }'s.
l.1772      }

? 
! Too many }'s.
l.1773    }

? 
! Too many }'s.
l.1774  }

? 
! Undefined control sequence.
<argument> \LaTeX3 error: 
                           The deprecated command '\luatex_if_engine:T' has ...
l.2053 \luatex_if_engine:T

? 

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! LaTeX error: "kernel/deprecated-command"
! 
! The deprecated command '\luatex_if_engine:T' has been or will be removed on
! 2017-01-01. Use instead '\sys_if_engine_luatex:T '.
! 
! See the LaTeX3 documentation for further information.
! 
! Type <return> to continue.
!...............................................  

l.2053 \luatex_if_engine:T

? 
(/home/manos/texmf/tex/latex/fontspec/fontspec.cfg)))
(/usr/local/texlive/2018/texmf-dist/tex/latex/caption/caption.sty
(/usr/local/texlive/2018/texmf-dist/tex/latex/caption/caption3.sty))
(/usr/local/texlive/2018/texmf-dist/tex/latex/caption/subcaption.sty)
(/usr/local/texlive/2018/texmf-dist/tex/xelatex/xgreek/xgreek.sty
Package `xgreek' version 3.0.1 by Apostolos Syropoulos)
Overfull \hbox (1141.06079pt too wide) in paragraph at lines 1767--10
[]\EU1/lmr/m/n/10 25x8X?                                                       



(./latex_example.aux)
(/usr/local/texlive/2018/texmf-dist/tex/latex/cbfonts-fd/lgrcmr.fd)
(/usr/local/texlive/2018/texmf-dist/tex/latex/tipa/t3cmr.fd)

LaTeX Font Warning: Font shape `LGR/CMUSerif(0)/m/n' undefined
(Font)              using `LGR/cmr/m/n' instead on input line 13.

*** you should *not* be loading the inputenc package
*** XeTeX expects the source to be in UTF8 encoding
*** some features of other encodings may conflict, resulting in poor output.

! LaTeX Error: Command \nobreakspace unavailable in encoding LGR.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.27   \caption{Αυτό είναι μια επικεφαλίδα}

? 

! LaTeX Error: Command \nobreakspace unavailable in encoding LGR.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.27   \caption{Αυτό είναι μια επικεφαλίδα}

? 

! LaTeX Error: Command \nobreakspace unavailable in encoding LGR.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.27   \caption{Αυτό είναι μια επικεφαλίδα}

? 

! LaTeX Error: Command \nobreakspace unavailable in encoding LGR.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.27   \caption{Αυτό είναι μια επικεφαλίδα}

? 
[1] (./latex_example.aux)

LaTeX Font Warning: Some font shapes were not available, defaults substituted.

 )
Output written on latex_example.pdf (1 page).
Transcript written on latex_example.log.

先感谢您。

答案1

LGR无论如何,使用最新的 TeX 发行版时,您都不想加载编码。使用 XeLaTeX 时更是如此,因为加载它实际上是错误的。加载xgreek是可选的(我不推荐这样做)。

最重要的是,您需要一种支持希腊语的主字体,而默认的拉丁现代字体不支持。

\documentclass{article}

\usepackage[main=greek,english]{babel}
\usepackage{fontspec}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{xgreek}
\usepackage{graphicx}

\setmainfont{CMU Serif}

\begin{document}

\today

\begin{figure}[htp]
  \centering
  \begin{subfigure}[b]{0.4\textwidth}
    \includegraphics[width=\textwidth]{example-image}
    \subcaption{Αυτό είναι μια υπο-επικεφαλίδα}
  \end{subfigure}
  \begin{subfigure}[b]{0.4\textwidth}
    \includegraphics[width=\textwidth]{example-image}
    \subcaption{Αυτό είναι μια υπο-επικεφαλίδα}
  \end{subfigure}
  \caption{Αυτό είναι μια επικεφαλίδα}
\end{figure}

\end{document}

在此处输入图片描述

选择任何支持希腊语的字体而不是 CMU Serif。

如果\setmainfont{CMU Serif}不起作用,因为操作系统无法使用该字体,则可以进行以下调用

\setmainfont{cmun}[
  Extension=.otf,
  UprightFont=*rm,
  ItalicFont=*ti,
  BoldFont=*bx,
  BoldItalicFont=*bi,
]

相关内容