列表内的阿拉伯语文字

列表内的阿拉伯语文字

背景

我正在尝试使用该包让阿拉伯语文本显示在 HTML 代码标记内listings。代码不会产生任何错误,但也不会显示阿拉伯语文本。下面的最小工作示例从以下帖子中汲取灵感,我尝试复制它:列表的阿拉伯字体

最小工作示例(MWE)

\documentclass[cmyk]{article}

\usepackage[utf8]{inputenc}
\usepackage[OT6,LAE,T1]{fontenc}
\usepackage{xcolor}
\usepackage{listings}
\usepackage{arabtex}

% ----------------------------------------------------------------------
%  Definition of colors
% ----------------------------------------------------------------------

\definecolor{editorGray}{gray}{0}
\definecolor{editorPurple}{cmyk}{0.75, 1, 0, 0}
\definecolor{editorDarkOrange}{cmyk}{0, 0.8, 0.9, 0}
\definecolor{editorBlue}{cmyk}{1, 0.35, 0, 0}
\definecolor{editorPink}{cmyk}{0, 1, 0, 0}

% ----------------------------------------------------------------------
%  HTML
% ----------------------------------------------------------------------
\lstdefinelanguage{HTML5}{
  language=html,
  sensitive=true,
  tagstyle=\color{editorBlue},
  markfirstintag=true,
  alsoletter={!-'}
}

% ----------------------------------------------------------------------
%  Code style
% ----------------------------------------------------------------------
\lstset{%
  % General design
  inputencoding=utf8,
  backgroundcolor=\color{white},
  basicstyle=\ttfamily\upshape\lst@ifdisplaystyle\tiny\fi,
  frame=l,
  float,
  belowskip=0pt,
  escapeinside=`',
  % Line numbers
  framesep=5pt,
  xleftmargin={14pt},
  numbers=left,
  stepnumber=1,
  firstnumber=1,
  numberfirstline=true,
  numberstyle=\color{black},
  % Code design
  identifierstyle=\color{editorDarkOrange},
  keywordstyle=[1]\color{editorPink},
  keywordstyle=[7]\color{black},
  commentstyle=\color{editorGray},
  stringstyle=\color{editorPurple},
  % Code
  language=HTML5,
  alsodigit={.:},
  tabsize=2,
  showtabs=false,
  showspaces=false,
  showstringspaces=false,
  keepspaces=true,
  extendedchars=true,
  breaklines=false
}

% ----------------------------------------------------------------------
%  Color style for < and > for code examples
% ----------------------------------------------------------------------
\gdef\lst@BeginTag{%
    \lst@DelimOpen
        \lst@ifextags\else
        {\let\lst@ifkeywords\iftrue
         \lst@ifmarkfirstintag\lst@firstintagtrue\fi\color{editorBlue}}}
\gdef\lst@EndTag{\lst@DelimClose\lst@ifextags\else\color{editorBlue}}

\begin{document}

\begin{lstlisting}[language=HTML5,numbers=left,firstnumber=1]
<!DOCTYPE html>
<html lang="sv">
  <head>
    <meta charset="utf-8">
    <title>`\color{editorDarkOrange}HTML and CSS'</title>
    <link rel="stylesheet" href="style.css">
  </head>
  <body>
    <main>
      <section>
        <h1>`\<گوشی>'</h1>
        <p>`\color{editorDarkOrange}The idea of HTML was developed in 1989 by Tim Berners-Lee.'</p>
      </section>
    </main>
  </body>
</html>
\end{lstlisting}

\end{document}

电流输出 在此处输入图片描述

期望输出

  1. 在 HTML 标签内显示阿拉伯文本。
  2. 删除似乎是由阿拉伯文本引起的左框架线的间距。

答案1

如果没有 arabtex,您只需要LAE选择 fontenc 包并使用 激活从右到左的书写\TeXXeTstate=1

\documentclass[cmyk]{article}

\usepackage[utf8]{inputenc}
\usepackage[LAE,T1]{fontenc}
\usepackage{xcolor}
\usepackage{listings}


% ----------------------------------------------------------------------
%  Definition of colors
% ----------------------------------------------------------------------

\definecolor{editorGray}{gray}{0}
\definecolor{editorPurple}{cmyk}{0.75, 1, 0, 0}
\definecolor{editorDarkOrange}{cmyk}{0, 0.8, 0.9, 0}
\definecolor{editorBlue}{cmyk}{1, 0.35, 0, 0}
\definecolor{editorPink}{cmyk}{0, 1, 0, 0}

% ----------------------------------------------------------------------
%  HTML
% ----------------------------------------------------------------------
\lstdefinelanguage{HTML5}{
  language=html,
  sensitive=true,
  tagstyle=\color{editorBlue},
  markfirstintag=true,
  alsoletter={!-'}
}

% ----------------------------------------------------------------------
%  Code style
% ----------------------------------------------------------------------
\lstset{%
  % General design
  inputencoding=utf8,
  backgroundcolor=\color{white},
  basicstyle=\ttfamily\upshape\lst@ifdisplaystyle\tiny\fi,
  frame=l,
  float,
  belowskip=0pt,
  escapeinside=`',
  % Line numbers
  framesep=5pt,
  xleftmargin={14pt},
  numbers=left,
  stepnumber=1,
  firstnumber=1,
  numberfirstline=true,
  numberstyle=\color{black},
  % Code design
  identifierstyle=\color{editorDarkOrange},
  keywordstyle=[1]\color{editorPink},
  keywordstyle=[7]\color{black},
  commentstyle=\color{editorGray},
  stringstyle=\color{editorPurple},
  % Code
  language=HTML5,
  alsodigit={.:},
  tabsize=2,
  showtabs=false,
  showspaces=false,
  showstringspaces=false,
  keepspaces=true,
  extendedchars=true,
  breaklines=false
}

% ----------------------------------------------------------------------
%  Color style for < and > for code examples
% ----------------------------------------------------------------------
\gdef\lst@BeginTag{%
    \lst@DelimOpen
        \lst@ifextags\else
        {\let\lst@ifkeywords\iftrue
         \lst@ifmarkfirstintag\lst@firstintagtrue\fi\color{editorBlue}}}
\gdef\lst@EndTag{\lst@DelimClose\lst@ifextags\else\color{editorBlue}}

% To write arabic

\TeXXeTstate=1
\def\textRL#1{\bgroup\fontencoding{LAE}\selectfont\beginR #1\endR\egroup}

\begin{document}



\begin{lstlisting}[language=HTML5,numbers=left,firstnumber=1]
<!DOCTYPE html>
<html lang="sv">
  <head>
    <meta charset="utf-8">
    <title>`\color{editorDarkOrange}HTML and CSS'</title>
    <link rel="stylesheet" href="style.css">
  </head>
  <body>
    <main>
      <section>
        <h1>`\textRL{كوشي}'</h1>
        <p>`\color{editorDarkOrange}The idea of HTML was developed in 1989 by Tim Berners-Lee.'</p>
      </section>
    </main>
  </body>
</html>
\end{lstlisting}

\end{document}

在此处输入图片描述

相关内容