在 LaTeX .cls 文件中支持阿拉伯语

在 LaTeX .cls 文件中支持阿拉伯语

您能否在以下 .cls 文件中添加一些行以支持阿拉伯语?

\ProvidesClass{bandar-cv}[2012/04/30 CV class]
\NeedsTeXFormat{LaTeX2e}

\DeclareOption{print}{\def\@cv@print{}}
\DeclareOption*{%
  \PassOptionsToClass{\CurrentOption}{article}%
}
\ProcessOptions\relax
\LoadClass{article}


%%%%%%%%%%
% Colors %
%%%%%%%%%%

\RequirePackage{xcolor}

\definecolor{white}{RGB}{255,255,255}

\definecolor{darkgray}{HTML}{333333}
\definecolor{gray}{HTML}{4D4D4D}
\definecolor{lightgray}{HTML}{999999}

\definecolor{green}{HTML}{C2E15F}
\definecolor{orange}{HTML}{FDA333}
\definecolor{purple}{HTML}{D3A4F9}
\definecolor{red}{HTML}{FB4485}
\definecolor{blue}{HTML}{6CE0F1}

\ifdefined\@cv@print
  \colorlet{green}{gray}
  \colorlet{orange}{gray}
  \colorlet{purple}{gray}
  \colorlet{brown}{gray}
  \colorlet{red}{gray}
  \colorlet{blue}{gray}
  \colorlet{fillheader}{white}
  \colorlet{header}{gray}
\else
  \colorlet{fillheader}{gray}
  \colorlet{header}{white}
\fi
\colorlet{textcolor}{gray}
\colorlet{headercolor}{gray}

%%%%%%%%%
% Fonts %
%%%%%%%%%
%\RequirePackage[arabic,english]

\RequirePackage[quiet]{fontspec}
\RequirePackage[math-style=TeX,vargreek-shape=unicode]{unicode-math}

\newfontfamily\bodyfont[]{Helvetica Neue}
\newfontfamily\thinfont[]{Helvetica Neue UltraLight}
\newfontfamily\headingfont[]{Helvetica Neue Condensed Bold}

\defaultfontfeatures{Mapping=tex-text}
\setmainfont[Mapping=tex-text, Color=textcolor]{Helvetica Neue Light}

%\setmathfont{XITS Math}

%%%%%%%%%%
% Header %
%%%%%%%%%%

\RequirePackage{tikz}

\newcommand{\rolefont}{%
  \fontsize{14pt}{24pt}\selectfont%
  \thinfont%
  \color{white}%
}

\newcommand{\header}[3]{%
  \begin{tikzpicture}[remember picture,overlay]
    \node [rectangle, fill=fillheader, anchor=north, minimum width=\paperwidth, minimum height=4cm] (box) at (current page.north){};
    \node [anchor=center] (name) at (box) {%
      \fontsize{40pt}{72pt}\color{header}%
      {\thinfont #1}{\bodyfont  #2}
    };
    \node [anchor=north] at (name.south) {%
      \fontsize{14pt}{24pt}\color{header}%
      \thinfont #3%
    };
  \end{tikzpicture}
  \vspace{2.5cm}
  \vspace{-2\parskip}
}


%%%%%%%%%%%%%
% Structure %
%%%%%%%%%%%%%
\RequirePackage{parskip}

\newcounter{colorCounter}
\def\@sectioncolor#1#2#3{%
  {%
    \color{%
      \ifcase\value{colorCounter}%
        blue\or%
        red\or%
        orange\or%
        green\or%
        purple\or%
        brown\else%
        headercolor\fi%
    } #1#2#3%
  }%
  \stepcounter{colorCounter}%
}

\renewcommand{\section}[1]{
  \par\vspace{\parskip}
  {%
    \LARGE\headingfont\color{headercolor}%
    \@sectioncolor #1%
  }
  \par\vspace{\parskip}
}

\renewcommand{\subsection}[1]{
  \par\vspace{.5\parskip}%
  {\Large\headingfont\color{headercolor} #1}
  \par\vspace{.25\parskip}%
}

\renewcommand{\subsubsection}[2]{
  \par\vspace{.5\parskip}%
  {\Large\headingfont\color{headercolor} #2}
  \par\vspace{.25\parskip}%
}

\pagestyle{empty}


%%%%%%%%%%%%%%%%%%%%
% List environment %
%%%%%%%%%%%%%%%%%%%%

\setlength{\tabcolsep}{0pt}
\newenvironment{entrylist}{%
  \begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}ll}
}{%
  \end{tabular*}
}
\renewcommand{\bfseries}{\headingfont\color{headercolor}}
\newcommand{\entry}[4]{%
  #1&\parbox[t]{11.8cm}{%
    \textbf{#2}%
    \hfill%
    {\footnotesize\addfontfeature{Color=lightgray} #3}\\%
    #4\vspace{\parsep}%
  }\\}


%%%%%%%%%%%%%%
% Side block %
%%%%%%%%%%%%%%

\RequirePackage[absolute,overlay]{textpos}
\setlength{\TPHorizModule}{1cm}
\setlength{\TPVertModule}{1cm}
\newenvironment{aside}{%
  \let\oldsection\section
  \renewcommand{\section}[1]{
    \par\vspace{\baselineskip}{\Large\headingfont\color{headercolor} ##1}
  }
  \begin{textblock}{3.6}(1.5, 4.33)
  \begin{flushright}
  \obeycr
}{%
  \restorecr
  \end{flushright}
  \end{textblock}
  \let\section\oldsection
}

%%%%%%%%%%%%%%%%
% Bibliography %
%%%%%%%%%%%%%%%%

\RequirePackage[style=verbose, maxnames=99, sorting=ydnt]{biblatex}

\DeclareFieldFormat[article]{title}{#1\par}
\DeclareFieldFormat[book]{title}{#1\par}
\DeclareFieldFormat[inproceedings]{title}{#1\par}
\DeclareFieldFormat[misc]{title}{#1\par}
\DeclareFieldFormat[report]{title}{#1\par}

\DeclareBibliographyDriver{article}{%
  \printfield{title}%
  \newblock%
  \printnames{author}%
  \par%
  \newblock%
  {%
    \footnotesize\addfontfeature{Color=lightgray}\itshape%
    \usebibmacro{journal+issuetitle}%
    \setunit{\space}%
    \printfield{pages}%
    \newunit%
    \printlist{publisher}%
    \setunit*{\addcomma\space}%
    \printfield{year}%
    \newunit%
  }
  \par\vspace{0.3\baselineskip}
}

\DeclareBibliographyDriver{book}{%
  \printfield{title}%
  \newblock%
  \printnames{author}%
  \par%
  \newblock%
  {%
    \footnotesize\addfontfeature{Color=lightgray}\itshape%
    \printlist{publisher}%
    \setunit*{\addcomma\space}%
    \printfield{note}%
    \setunit*{\addcomma\space}%
    \printfield{year}%
    \setunit{\addcomma\space}%
    \printlist{location}%
    \newunit%
  }
  \par\vspace{0.3\baselineskip}
}


\DeclareBibliographyDriver{inproceedings}{%
  \printfield{title}%
  \newblock%
  \printnames{author}%
  \par%
  \newblock%
  {%
    \footnotesize\addfontfeature{Color=lightgray}%
    \printfield{booktitle}%
    \setunit{\addcomma\space}%
    \printfield{year}%
    \setunit{\addcomma\space}%
    \printlist{location}%
    \newunit%
  }
  \par\vspace{0.3\baselineskip}
}

\DeclareBibliographyDriver{misc}{%
  \printfield{title}%
  \newblock%
  \printnames{author}%
  \par%
  \newblock%
  {%
    \footnotesize\addfontfeature{Color=lightgray}\itshape%
    \printfield{booktitle}%
    \setunit*{\addcomma\space}%
    \printfield{note}%
    \setunit*{\addcomma\space}%
    \printfield{year}%
    \setunit{\addcomma\space}%
    \printlist{location}%
    \newunit%
  }
  \par\vspace{0.3\baselineskip}
}

\DeclareBibliographyDriver{report}{%
  \printfield{title}%
  \newblock%
  \printnames{author}%
  \par%
  \newblock%
  {%
    \footnotesize\addfontfeature{Color=lightgray}\itshape%
    \printfield{type}%
    \setunit{\space}%
    \printfield{number}%
    \setunit{\addcomma\space}%
    \printfield{year}%
    \newunit%
  }
  \par\vspace{0.3\baselineskip}
}

\DeclareNameFormat{author}{%
  \small\addfontfeature{Color=lightgray}%
  \ifblank{#3}{}{#3\space}#1%
  \ifthenelse{\value{listcount}<\value{liststop}}
    {\addcomma\space}
    {}%
}

\defbibheading{bibheading}[\bibname]{%
   \subsubsection*{#1}
   \markboth{#1}{#1}
}

\newcommand{\printbibsection}[2]{
  \begin{refsection}
    \nocite{*}
    \printbibliography[sorting=chronological, type={#1}, title={#2}, heading=bibheading]
  \end{refsection}
}

\DeclareSortingScheme{chronological}{
  \sort[direction=descending]{\field{year}}
  \sort[direction=descending]{\field{month}}
}



%%%%%%%%%%%%%%%%
% Other tweaks %
%%%%%%%%%%%%%%%%

\RequirePackage[left=6.1cm,top=2cm,right=1.5cm,bottom=2.5cm,nohead,nofoot]{geometry}
\RequirePackage{hyperref}
\hypersetup{
    colorlinks=false,       
    linkcolor=red,          
    citecolor=red,        
    filecolor=red,      
    urlcolor = red}

% A fix for \href{}{} colors not working with fontspec
\makeatletter
\def\HyColor@@@@UseColor#1\@nil{\addfontfeatures{Color=#1}}
\makeatother

答案1

要在你的课程中添加阿拉伯语,你首先需要一个阿拉伯字体,这可以使用 fontspec 来完成

\newfontfamily\arabicfont[Script=Arabic]{Amiri}

您还需要宏来更改提供的文本方向bidi 包,对于从右到左的短文本,您可以使用,或者对于长文本\RL{arabic text}使用环境RTL

\begin{RTL}
arabic text ......
\end{RTL}

  1. 在类文件中添加阿拉伯字体

    \ProvidesClass{bandar-cv}[2012/04/30 CV class]
    \NeedsTeXFormat{LaTeX2e}
    
    \DeclareOption{print}{\def\@cv@print{}}
    \DeclareOption*{%
      \PassOptionsToClass{\CurrentOption}{article}%
    }
    \ProcessOptions\relax
    \LoadClass{article}
    
    
    %%%%%%%%%%
    % Colors %
    %%%%%%%%%%
    
    \RequirePackage{xcolor}
    
    \definecolor{white}{RGB}{255,255,255}
    
    \definecolor{darkgray}{HTML}{333333}
    \definecolor{gray}{HTML}{4D4D4D}
    \definecolor{lightgray}{HTML}{999999}
    
    \definecolor{green}{HTML}{C2E15F}
    \definecolor{orange}{HTML}{FDA333}
    \definecolor{purple}{HTML}{D3A4F9}
    \definecolor{red}{HTML}{FB4485}
    \definecolor{blue}{HTML}{6CE0F1}
    
    \ifdefined\@cv@print
      \colorlet{green}{gray}
      \colorlet{orange}{gray}
      \colorlet{purple}{gray}
      \colorlet{brown}{gray}
      \colorlet{red}{gray}
      \colorlet{blue}{gray}
      \colorlet{fillheader}{white}
      \colorlet{header}{gray}
    \else
      \colorlet{fillheader}{gray}
      \colorlet{header}{white}
    \fi
    \colorlet{textcolor}{gray}
    \colorlet{headercolor}{gray}
    
    %%%%%%%%%
    % Fonts %
    %%%%%%%%%
    %\RequirePackage[arabic,english]
    
    \RequirePackage[quiet]{fontspec}
    \newfontfamily\arabicfont[Script=Arabic]{Amiri} % <-- add arabic font 
    \RequirePackage[math-style=TeX,vargreek-shape=unicode]{unicode-math}
    
    \newfontfamily\bodyfont[]{Helvetica Neue}
    \newfontfamily\thinfont[]{Helvetica Neue UltraLight}
    \newfontfamily\headingfont[]{Helvetica Neue Condensed Bold}
    
    \defaultfontfeatures{Mapping=tex-text}
    \setmainfont[Mapping=tex-text, Color=textcolor]{Helvetica Neue Light}
    
    %\setmathfont{XITS Math}
    
    %%%%%%%%%%
    % Header %
    %%%%%%%%%%
    
    \RequirePackage{tikz}
    
    \newcommand{\rolefont}{%
      \fontsize{14pt}{24pt}\selectfont%
      \thinfont%
      \color{white}%
    }
    
    \newcommand{\header}[3]{%
      \begin{tikzpicture}[remember picture,overlay]
        \node [rectangle, fill=fillheader, anchor=north, minimum 
    width=\paperwidth, minimum height=4cm] (box) at (current page.north){};
        \node [anchor=center] (name) at (box) {%
          \fontsize{40pt}{72pt}\color{header}%
          {\thinfont #1}{\bodyfont  #2}
        };
        \node [anchor=north] at (name.south) {%
          \fontsize{14pt}{24pt}\color{header}%
          \thinfont #3%
        };
      \end{tikzpicture}
      \vspace{2.5cm}
      \vspace{-2\parskip}
    }
    
    
    %%%%%%%%%%%%%
    % Structure %
    %%%%%%%%%%%%%
    \RequirePackage{parskip}
    
    \newcounter{colorCounter}
    \def\@sectioncolor#1#2#3{%
      {%
        \color{%
          \ifcase\value{colorCounter}%
            blue\or%
            red\or%
            orange\or%
            green\or%
            purple\or%
            brown\else%
            headercolor\fi%
        } #1#2#3%
      }%
      \stepcounter{colorCounter}%
    }
    
    \renewcommand{\section}[1]{
      \par\vspace{\parskip}
      {%
        \LARGE\headingfont\color{headercolor}%
        \@sectioncolor #1%
      }
      \par\vspace{\parskip}
    }
    
    \renewcommand{\subsection}[1]{
      \par\vspace{.5\parskip}%
      {\Large\headingfont\color{headercolor} #1}
      \par\vspace{.25\parskip}%
    }
    
    \renewcommand{\subsubsection}[2]{
      \par\vspace{.5\parskip}%
      {\Large\headingfont\color{headercolor} #2}
      \par\vspace{.25\parskip}%
    }
    
    \pagestyle{empty}
    
    
    %%%%%%%%%%%%%%%%%%%%
    % List environment %
    %%%%%%%%%%%%%%%%%%%%
    
    \setlength{\tabcolsep}{0pt}
    \newenvironment{entrylist}{%
      \begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}ll}
    }{%
      \end{tabular*}
    }
    \renewcommand{\bfseries}{\headingfont\color{headercolor}}
    \newcommand{\entry}[4]{%
      #1&\parbox[t]{11.8cm}{%
        \textbf{#2}%
        \hfill%
        {\footnotesize\addfontfeature{Color=lightgray} #3}\\%
        #4\vspace{\parsep}%
      }\\}
    
    
    %%%%%%%%%%%%%%
    % Side block %
    %%%%%%%%%%%%%%
    
    \RequirePackage[absolute,overlay]{textpos}
    \setlength{\TPHorizModule}{1cm}
    \setlength{\TPVertModule}{1cm}
    \newenvironment{aside}{%
      \let\oldsection\section
      \renewcommand{\section}[1]{
        \par\vspace{\baselineskip}{\Large\headingfont\color{headercolor} ##1}
      }
      \begin{textblock}{3.6}(1.5, 4.33)
      \begin{flushright}
      \obeycr
    }{%
      \restorecr
      \end{flushright}
      \end{textblock}
      \let\section\oldsection
    }
    
    %%%%%%%%%%%%%%%%
    % Bibliography %
    %%%%%%%%%%%%%%%%
    
    \RequirePackage[style=verbose, maxnames=99, sorting=ydnt]{biblatex}
    
    \DeclareFieldFormat[article]{title}{#1\par}
    \DeclareFieldFormat[book]{title}{#1\par}
    \DeclareFieldFormat[inproceedings]{title}{#1\par}
    \DeclareFieldFormat[misc]{title}{#1\par}
    \DeclareFieldFormat[report]{title}{#1\par}
    
    \DeclareBibliographyDriver{article}{%
      \printfield{title}%
      \newblock%
      \printnames{author}%
      \par%
      \newblock%
      {%
        \footnotesize\addfontfeature{Color=lightgray}\itshape%
        \usebibmacro{journal+issuetitle}%
        \setunit{\space}%
        \printfield{pages}%
        \newunit%
        \printlist{publisher}%
        \setunit*{\addcomma\space}%
        \printfield{year}%
        \newunit%
      }
      \par\vspace{0.3\baselineskip}
    }
    
    \DeclareBibliographyDriver{book}{%
      \printfield{title}%
      \newblock%
      \printnames{author}%
      \par%
      \newblock%
      {%
        \footnotesize\addfontfeature{Color=lightgray}\itshape%
        \printlist{publisher}%
        \setunit*{\addcomma\space}%
        \printfield{note}%
        \setunit*{\addcomma\space}%
        \printfield{year}%
        \setunit{\addcomma\space}%
        \printlist{location}%
        \newunit%
      }
      \par\vspace{0.3\baselineskip}
    }
    
    
    \DeclareBibliographyDriver{inproceedings}{%
      \printfield{title}%
      \newblock%
      \printnames{author}%
      \par%
      \newblock%
      {%
        \footnotesize\addfontfeature{Color=lightgray}%
        \printfield{booktitle}%
        \setunit{\addcomma\space}%
        \printfield{year}%
        \setunit{\addcomma\space}%
        \printlist{location}%
        \newunit%
      }
      \par\vspace{0.3\baselineskip}
    }
    
    \DeclareBibliographyDriver{misc}{%
      \printfield{title}%
      \newblock%
      \printnames{author}%
      \par%
      \newblock%
      {%
        \footnotesize\addfontfeature{Color=lightgray}\itshape%
        \printfield{booktitle}%
        \setunit*{\addcomma\space}%
        \printfield{note}%
        \setunit*{\addcomma\space}%
        \printfield{year}%
        \setunit{\addcomma\space}%
        \printlist{location}%
        \newunit%
      }
      \par\vspace{0.3\baselineskip}
    }
    
    \DeclareBibliographyDriver{report}{%
      \printfield{title}%
      \newblock%
      \promma\space}
        {}%
    }
    
    \defbibheading{bibheading}[\bibname]{%
       \subsubsection*{#1}
       \markboth{#1}{#1}
    }
    
    \newcommand{\printbibsection}[2]{
      \begin{refsection}
        \nocite{*}
        \printbibliography[sorting=chronological, type={#1}, title={#2}, 
     heading=bibheading]
      \end{refsection}
    }
    
    \DeclareSortingScheme{chronological}{
      \sort[direction=descending]{\field{year}}
      \sort[direction=descending]{\field{month}}
    }
    
    
    
    %%%%%%%%%%%%%%%%
    % Other tweaks %
    %%%%%%%%%%%%%%%%
    
    \RequirePackage[left=6.1cm,top=2cm,right=1.5cm,bottom=2.5cm,nohead,nofoot] 
    {geometry}
    \RequirePackage{hyperref}
    \hypersetup{
        colorlinks=false,       
        linkcolor=red,          
        citecolor=red,        
        filecolor=red,      
        urlcolor = red}
    
    % A fix for \href{}{} colors not working with fontspec
    \makeatletter
    \def\HyColor@@@@UseColor#1\@nil{\addfontfeatures{Color=#1}}
    \makeatother
    
  2. 在你的 tex 文件中添加bidi从右到左书写的包( bidi 应该是你加载的最后一个包)

    \documentclass{bandar-cv}
    % add your packages here 
    \usepackage{bidi}
    
    \begin{document}
    
    % write short arabic text with 
    \RL{\arabicfont   نص عربي قصير}
    
    % write long arabic text with 
    
    \begin{RTL}
    \arabicfont
    نص عربي طويل به العديد من الأسطر 
    ........
    ........ 
    \end{RTL} 
    
    \end{document}
    

答案2

我宁愿使用polyglossia阿拉伯数字(我不知道为什么有人会使用拉丁数字和阿拉伯月份,您可以在下面看到区别):

\documentclass{article} \usepackage{polyglossia} 
\setotherlanguage[locale=mashriq]{arabic} %locale=maghrib (default) 
\setmainlanguage{english}

\usepackage{fontspec} 
\newfontfamily\arabicfont[Script=Arabic,Mapping=arabicdigits]{Amiri} % <-- add arabic font % add your packages here  \usepackage{bidi}

\begin{document}

% write short arabic text with  \RL{\arabicfont   نص عربي قصير}

% write long arabic text with 

\begin{RTL} \arabicfont 123456789 نص عربي طويل به العديد من الأسطر  ........ ........  \today  \end{RTL} 

\begin{Arabic} 123456789 نص عربي طويل به العديد من الأسطر 

\today \end{Arabic}

\end{document}

阿拉伯语和多语种

在您的文件中更改\usepackage为,您就可以开始了。\RequirePackage.cls

相关内容