我正在尝试写一个句子
该单词必须是 کا、کے 或 کی。
导入到 LaTeX 文档中。我尝试了几种将阿拉伯字符导入 LaTeX 的方法,以下是其中一种:乳胶中的阿拉伯语是我设法使它工作的唯一一个。但是,当我尝试将它的一个版本嵌入到包含多种不同语言单词的文档中时,它无法编译。我使用的是 Windows 10、TeXworks 编辑器、PdfLaTeX。(我对 LaTeX 还很陌生,这是我用它编写的第一份重要文档)。下面是我得到的错误(是的,我\begin{document}
的文档中确实有,如果我删除包导入和包含阿拉伯字符的部分,文档就可以正常编译。
这是一个“最小”的工作示例。此代码无法编译,但如果我注释掉包含如下注释的所有五行:%%%% If I comment out this and the rest of lines with this comment
,它将编译。
LaTeX 代码:
% -*- coding: utf-8 -*-
\documentclass{article}% use option titlepage to get the title on a page of its own.
\usepackage{blindtext}
\usepackage{graphicx}
\usepackage{devanagari}%Hindi word: {\dn kA}
\usepackage{url}
\usepackage{enumitem}
\usepackage{CJKutf8} % Japanese
\usepackage[T2A,T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[russian,english]{babel} % Cyrillic: Bulgarian
\usepackage[LGR,T1]{fontenc} % this and the next two lines for Ancient Greek, as well as the comment on the first line
\usepackage[utf8]{inputenc} % utf8 is required
\usepackage{textcomp}
\usepackage{arabtex} % Arabic: Urdu (doesn't work) %%%% If I comment out this and the rest of lines with this comment, it will compile
\usepackage{utf8} % Urdu (doesn't work) %%%% If I comment out this and the rest of lines with this comment, it will compile
\newcommand{\textgreek}[1]{\begingroup\fontencoding{LGR}\selectfont#1\endgroup}
\showboxdepth=\maxdimen
\showboxbreadth=\maxdimen
\hyphenation{tun-nis-ta-mis-oh-jei-den}
% numbering tutorials: https://latex.org/forum/viewtopic.php?t=12143 ; https://www.latex-tutorial.com/tutorials/lists/
% https://tex.stackexchange.com/questions/512584/arabic-alphabet-urdu-language-to-latex
\def\code#1{\texttt{#1}}
\title{Some random title}
\date{Some random date}
\author{Anonymous authors}
\begin{document}
\maketitle
\noindent Text:
\begin{enumerate}
\item This is an enumerated item
\item boom boom boom.
\item englanti.
\end{enumerate}
\section{Section}
\textbf{word} has four letters
\section{Devanagari transliteration workaround}
This works fine {\dn kA} yeah.
\section{Urdu (here's the problem)}
The word must be either
\<کا>%%%% If I comment out this and the rest of lines with this comment, it will compile
,
\<کے>%%%% If I comment out this and the rest of lines with this comment, it will compile
or
\<کی>%%%% If I comment out this and the rest of lines with this comment, it will compile
\section{Meaningless section}
\textbf{Some bold text here.}\newline\newline
\code{this is a code block}, boom.
\section{A Japanese character}
This is the only Japanese wod that I need: \begin{CJK}{UTF8}{min}の\end{CJK} and it works fine.
\section{Bulgarian}
This is a Bulgarian word: \foreignlanguage{russian}{на} and I need that as well.
\end{document}
错误信息:
This is pdfTeX, Version 3.14159265-2.6-1.40.20 (MiKTeX 2.9.7050 64-bit)
entering extended mode
(mwe.tex
LaTeX2e <2018-12-01>
("C:\Program Files\MiKTeX 2.9\tex/latex/base\article.cls"
Document Class: article 2018/09/03 v1.4i Standard LaTeX document class
("C:\Program Files\MiKTeX 2.9\tex/latex/base\size10.clo"))
("C:\Program Files\MiKTeX 2.9\tex/latex/blindtext\blindtext.sty"
("C:\Program Files\MiKTeX 2.9\tex/latex/tools\xspace.sty"))
("C:\Program Files\MiKTeX 2.9\tex/latex/graphics\graphicx.sty"
("C:\Program Files\MiKTeX 2.9\tex/latex/graphics\keyval.sty")
("C:\Program Files\MiKTeX 2.9\tex/latex/graphics\graphics.sty"
("C:\Program Files\MiKTeX 2.9\tex/latex/graphics\trig.sty")
("C:\Program Files\MiKTeX 2.9\tex/latex/graphics-cfg\graphics.cfg")
("C:\Program Files\MiKTeX 2.9\tex/latex/graphics-def\pdftex.def")))
("C:\Program Files\MiKTeX 2.9\tex/latex/devanagari\devanagari.sty")
("C:\Program Files\MiKTeX 2.9\tex/latex/url\url.sty")
("C:\Program Files\MiKTeX 2.9\tex/latex/enumitem\enumitem.sty")
("C:\Program Files\MiKTeX 2.9\tex/latex/cjk\CJKutf8.sty"
("C:\Program Files\MiKTeX 2.9\tex/generic/oberdiek\ifpdf.sty")
("C:\Program Files\MiKTeX 2.9\tex/latex/base\inputenc.sty")
("C:\Program Files\MiKTeX 2.9\tex/latex/cjk\CJK.sty"
("C:\Program Files\MiKTeX 2.9\tex/latex/cjk/mule\MULEenc.sty")
("C:\Program Files\MiKTeX 2.9\tex/latex/cjk\CJK.enc"))
("C:\Program Files\MiKTeX 2.9\tex/latex/base\fontenc.sty"))
("C:\Program Files\MiKTeX 2.9\tex/latex/base\fontenc.sty"
("C:\Program Files\MiKTeX 2.9\tex/latex/cyrillic\t2aenc.def"
("C:\Program Files\MiKTeX 2.9\tex/latex/base\t2aenc.dfu"))
("C:\Program Files\MiKTeX 2.9\tex/latex/base\t1enc.def"))
("C:\Program Files\MiKTeX 2.9\tex/generic/babel\babel.sty"
("C:\Program Files\MiKTeX 2.9\tex/generic/babel\switch.def")
*************************************
* Local config file bblopts.cfg used
*
("C:\Program Files\MiKTeX 2.9\tex/latex/arabi\bblopts.cfg")
("C:\Program Files\MiKTeX 2.9\tex/latex/babel-russian\russianb.ldf"
("C:\Program Files\MiKTeX 2.9\tex/generic/babel\babel.def"
("C:\Program Files\MiKTeX 2.9\tex/generic/babel\txtbabel.def")))
("C:\Program Files\MiKTeX 2.9\tex/latex/babel-english\english.ldf"))
("C:\Program Files\MiKTeX 2.9\tex/latex/base\fontenc.sty"
("C:\Program Files\MiKTeX 2.9\tex/latex/greek-fontenc\lgrenc.def"
("C:\Program Files\MiKTeX 2.9\tex/latex/greek-inputenc\lgrenc.dfu")
("C:\Program Files\MiKTeX 2.9\tex/latex/greek-fontenc\greek-fontenc.def"))
("C:\Program Files\MiKTeX 2.9\tex/latex/base\t1enc.def"))
("C:\Program Files\MiKTeX 2.9\tex/latex/base\textcomp.sty"
("C:\Program Files\MiKTeX 2.9\tex/latex/base\ts1enc.def"
("C:\Program Files\MiKTeX 2.9\tex/latex/base\ts1enc.dfu")))
("C:\Program Files\MiKTeX 2.9\tex/latex/arabtex\arabtex.sty"
! LaTeX Error: Missing \begin{document}.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.40 \let \xpa \expandafter
\def \xxpa {\xpa \xpa \xpa }
?
答案1
正如问题评论中所述,软件包arabtex
和devanagari
似乎存在兼容性问题。作为解决方案,我建议改用带有软件包polyglossia
和的XeLaTeX fontspec
。下面是一个小例子。请注意会自动polyglossia
加载fontspec
。
此外,您还需要包含文档中使用的语言字符的字体。此示例使用 Microsoft Windows 10 字体 Times New Roman、Nirmala UI 和 MS Gothic。如果未安装后两者,您可以从控制面板 > 字体 > 下载所有语言的字体进行安装。
更多信息可以从以下文档中找到polyglossia
和fontspec
包。
% !TEX encoding = UTF-8 Unicode
% !TEX TS-program = xelatex
\documentclass{article}
\usepackage{polyglossia}
\setdefaultlanguage{english}
\setotherlanguages{bulgarian,urdu,hindi}
% Document's main font (for English, Bulgarian and Urdu):
\setmainfont{Times New Roman}
% Font for Hindi text:
\newfontfamily\hindifont{Nirmala UI}
% Font and command for Japanese text:
\newfontfamily\japanesefont{MS Gothic}
\newcommand*{\textjapanese}[1]{{\japanesefont #1}}
\begin{document}
\noindent
Bulgarian: \textbulgarian{пример} \\
Urdu: \texturdu{مثال} \\
Hindi: \texthindi{उदाहरण} \\
Japanese: \textjapanese{例}
\end{document}
答案2
以下是使用最新 Babel 以及 XeLaTeX 或 LuaLaTeX 执行此操作的方法。代码中有一些注释。
\documentclass{article}
% For a mostly monolingual document, only declare explicitly the main
% language (minor languages are loaded on the fly). We need activate
% bidi writing; for a few words, the default is enough.
\usepackage[english, bidi=default]{babel}
% The default font doesn't include the required scripts,
% so we need some extra setup (fonts from TeXLive):
\babelfont[urdu]{rm}{Amiri}
\babelfont[japanese]{rm}{IPAexMincho}
\babelfont[bulgarian]{rm}{CMU Serif}
% With LuaLaTeX Harfbuzz is required in Hindi. XeLaTeX just
% ignores this setting.
\babelfont[hindi]{rm}[Renderer=Harfbuzz]{FreeSerif}
\title{Some random title}
\date{Some random date}
\author{Anonymous authors}
\begin{document}
\maketitle
Text.
\section{Section}
\textbf{word} has four letters
\section{Urdu (here's the problem)}
The word must be either \foreignlanguage{urdu}{کا}, or
\foreignlanguage{urdu}{کے}, or \foreignlanguage{urdu}{کی}
\section{A Japanese character}
This is the only Japanese word that I need:
\foreignlanguage{japanese}{の}.
\section{Bulgarian}
This is a Bulgarian word: \foreignlanguage{bulgarian}{на} and I need
that as well.
And hindi: \foreignlanguage{hindi}{हिन्दी}
\end{document}