更新

更新

我正在用希伯来语编写一个文件,并试图在其中给出讲座中的代码示例。但每次我切换到 LyX-Code 环境(和英语),并在空格后输入数字和符号时,编译时它们的顺序都会改变。

例如我想要的:

return 0;

我得到的是:

return ;0

注 1:我没有使用Insert -> Program Listing,因为出于某种原因,由于文件是希伯来语,所以它变得混乱。

注2:此问题仅当空格后涉及数字和符号时才会发生(如示例所示),如果涉及字母则不会发生。

注3:此问题仅在编译后的PDF中出现,在编辑器本身中它看起来与我想要的一样。

注意 4:每次我在一行中单独输入某种括号时,编译器都会将其方向切换。从}{。我假设此问题是由相同的原因引起的,但我还是会注意到它。

编辑:我被要求发布从 LyX 导出的 LaTeX 输出:

%% LyX 2.3.1 created this file.  For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[english,hebrew]{article}
\usepackage{fontspec}
\setmainfont[Ligatures=TeX]{Times New Roman}
\setsansfont[Ligatures=TeX]{Arial}
\setmonofont{Courier New}
\setlength{\parindent}{0bp}

\makeatletter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
\providecommand\textquotedblplain{%
  \bgroup\addfontfeatures{RawFeature=-tlig}\char34\egroup}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Textclass specific LaTeX commands.
\newenvironment{lyxcode}
    {\par\begin{list}{}{
        \setlength{\rightmargin}{\leftmargin}
        \setlength{\listparindent}{0pt}% needed for AMS classes
        \raggedright
        \setlength{\itemsep}{0pt}
        \setlength{\parsep}{0pt}
        \normalfont\ttfamily}%
     \item[]}
    {\end{list}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\usepackage[left]{lineno}
\linenumbers

\makeatother

\usepackage{polyglossia}
\setdefaultlanguage{hebrew}
\setotherlanguage{english}
\begin{document}
\begin{english}%
\begin{lyxcode}
\#include<stdio.h>

int~a~=~0;

int~main(void)

\{
\begin{lyxcode}
while~(a~<~10)

\{
\begin{lyxcode}
printf(\textquotedbl\%d\textquotedbl ,~a);

a~+=~1;
\end{lyxcode}
\}

return~0;
\end{lyxcode}
\}

\begin{hebrew}%
\end{hebrew}%
\end{lyxcode}
\end{english}

\end{document}

感谢您的帮助。

编辑2:此序言代码\let\hebrewfonttt\ttfamily似乎解决了该问题。

答案1

更新

哦!我明白了。问题是 Times New Roman、Arial 和 Courier 不支持希伯来语文字(仅支持字形)。

只需在序言中定义希伯来字体就足够了。

然后只需正常设置你的 LyX 代码列表,一切就都可以正常工作。

笔记

这仍然有一些问题(我设法在某些情况下解决了代码清单中的一些括号问题。)。如果您使用的字体能够正确支持希伯来语和英语(例如 FreeSerif、FreeSans、FreeMono),则无需在序言中放置任何内容。您只需指定basicstyle=\ttfamilylatin代码清单选项即可。

无论如何,根据您当前的字体选择,序言应该是这样的:

\newfontfamily\hebrewfont{Times New Roman}[Ligatures=TeX]
\newfontfamily\hebrewfontsf{Arial}[Ligatures=TeX]
\newfontfamily\hebrewfonttt{Courier New}

平均能量损失

#LyX 2.3 created this file. For more info see http://www.lyx.org/
\lyxformat 544
\begin_document
\begin_header
\save_transient_properties true
\origin unavailable
\textclass article
\begin_preamble
\newfontfamily\hebrewfont{Times New Roman}[Ligatures=TeX]
\newfontfamily\hebrewfontsf{Arial}[Ligatures=TeX]
\newfontfamily\hebrewfonttt{Courier New}
\end_preamble
\use_default_options true
\maintain_unincluded_children false
\language hebrew
\language_package auto
\inputencoding auto
\fontencoding global
\font_roman "default" "Times New Roman"
\font_sans "default" "Arial"
\font_typewriter "default" "Courier New"
\font_math "auto" "auto"
\font_default_family default
\use_non_tex_fonts true
\font_sc false
\font_osf false
\font_sf_scale 100 100
\font_tt_scale 100 100
\use_microtype false
\use_dash_ligatures true
\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\paperfontsize default
\spacing single
\use_hyperref false
\papersize default
\use_geometry false
\use_package amsmath 1
\use_package amssymb 1
\use_package cancel 1
\use_package esint 1
\use_package mathdots 1
\use_package mathtools 1
\use_package mhchem 1
\use_package stackrel 1
\use_package stmaryrd 1
\use_package undertilde 1
\cite_engine basic
\cite_engine_type default
\biblio_style plain
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\justification true
\use_refstyle 1
\use_minted 0
\index Index
\shortcut idx
\color #008000
\end_index
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\paragraph_indentation default
\is_math_indent 0
\math_numbering_side default
\quotes_style english
\dynamic_quotes 0
\papercolumns 1
\papersides 1
\paperpagestyle empty
\tracking_changes false
\output_changes false
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\end_header

\begin_body

\begin_layout Standard
יברית
\end_layout

\begin_layout Standard

\lang english
\begin_inset listings
lstparams "language=C,numbers=left,tabsize=4,basicstyle={\ttfamily}"
inline false
status open

\begin_layout Plain Layout

#include <stdio.h>
\end_layout

\begin_layout Plain Layout

int a = 0;
\end_layout

\begin_layout Plain Layout

int main(void)
\end_layout

\begin_layout Plain Layout

{
\end_layout

\begin_layout Plain Layout

    while (a < 10)
\end_layout

\begin_layout Plain Layout

    {
\end_layout

\begin_layout Plain Layout

        printf("%d", a);
\end_layout

\begin_layout Plain Layout

        a += 1;
\end_layout

\begin_layout Plain Layout

    }
\end_layout

\begin_layout Plain Layout

    return 0;
\end_layout

\begin_layout Plain Layout

}
\end_layout

\end_inset


\end_layout

\begin_layout Standard
יברית
\end_layout

\begin_layout Standard

\lang english
English
\end_layout

\end_body
\end_document

LyX 视图

在此处输入图片描述

PDF 输出

在此处输入图片描述


导出 LaTeX 以供比较

这是 LyX 导出到 时提供的内容。这会在我的系统上LaTeX (XeTeX)编译清理。xelatex

%% LyX 2.3.0 created this file.  For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\listfiles
\documentclass{article}
\usepackage{fontspec}
\setmainfont[Mapping=tex-text]{Times New Roman}
\setsansfont[Mapping=tex-text]{Arial}
\setmonofont{Courier New}
\pagestyle{empty}

\makeatletter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
\providecommand\textquotedblplain{%
  \bgroup\addfontfeatures{Mapping=}\char34\egroup}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\newfontfamily\hebrewfont{Times New Roman}[Ligatures=TeX]
\newfontfamily\hebrewfontsf{Arial}[Ligatures=TeX]
\newfontfamily\hebrewfonttt{Courier New}

\makeatother

\usepackage{listings}
\usepackage{polyglossia}
\setdefaultlanguage{hebrew}
\setotherlanguage{english}
\addto\captionsenglish{\renewcommand{\lstlistingname}{Listing}}
\addto\captionshebrew{\renewcommand{\lstlistingname}{רישום קוד}}
\renewcommand{\lstlistingname}{רישום קוד}

\begin{document}
יברית

\begin{english}[variant=american]%
\begin{lstlisting}[language=C,numbers=left,tabsize=4,basicstyle={\ttfamily}]
#include <stdio.h>
int a = 0;
int main(void)
{
    while (a < 10)
    {
        printf("%d", a);
        a += 1;
    }
    return 0;
}
\end{lstlisting}

\end{english}%
יברית

\begin{english}[variant=american]%
English
\end{english}%

\end{document}

\listfiles输出

\listfiles为了帮助调试,这是在文件顶部进行编译时的输出:

 *File List*
 article.cls    2014/09/29 v1.4h Standard LaTeX document class
  size10.clo    2014/09/29 v1.4h Standard LaTeX file (size option)
fontspec.sty    2018/07/30 vv2.6h Font selection for XeLaTeX and LuaLaTeX
  xparse.sty    2018-05-12 L3 Experimental document command parser
   expl3.sty    2018-06-14 L3 programming layer (loader) 
expl3-code.tex    2018-06-14 L3 programming layer 
l3xdvipdfmx.def    
fontspec-xetex.sty    2018/07/30 vv2.6h Font selection for XeLaTeX and LuaLaTeX

 fontenc.sty
   tuenc.def    2017/04/05 v2.0i Standard LaTeX file
fontspec.cfg
listings.sty    2015/06/04 1.6 (Carsten Heinz)
  keyval.sty    2014/10/28 v1.15 key=value parser (DPC)
 lstmisc.sty    2015/06/04 1.6 (Carsten Heinz)
listings.cfg    2015/06/04 1.6 listings configuration
polyglossia.sty    2018/04/07 v1.43 Alternative to Babel for XeLaTeX and LuaLaT
eX
etoolbox.sty    2018/08/19 v2.5f e-TeX tools for LaTeX (JAW)
makecmds.sty    2009/09/03 v1.0a extra command making commands
 xkeyval.sty    2014/12/03 v2.7a package option processing (HA)
 xkeyval.tex    2014/12/03 v2.7a key=value parser (HA)
ifluatex.sty    2016/05/16 v1.4 Provides the ifluatex switch (HO)
 ifxetex.sty    2010/09/12 v0.6 Provides ifxetex conditional
gloss-hebrew.ldf    polyglossia: module for hebrew
hebrewcal.sty    2015/04/17 v2.6 Hebrew calendar for polyglossia (adapted from 
hebcal.sty in Babel)
    bidi.sty    2018/08/12 v33.1 Bidirectional typesetting in plain TeX and LaT
eX
   iftex.sty    2013/04/04 v0.2 Provides if(tex) conditional for PDFTeX, XeTeX,
 and LuaTeX
biditools.sty    2018/02/22 v1.4 Programming tools for bidi package
zref-abspage.sty    2016/05/21 v2.26 Module abspage for zref (HO)
zref-base.sty    2016/05/21 v2.26 Module base for zref (HO)
 ltxcmds.sty    2016/05/16 v1.23 LaTeX kernel commands for general use (HO)
infwarerr.sty    2016/05/16 v1.4 Providing info/warning/error messages (HO)
kvsetkeys.sty    2016/05/16 v1.17 Key value parser (HO)
etexcmds.sty    2016/05/16 v1.6 Avoid name clashes with e-TeX commands (HO)
kvdefinekeys.sty    2016/05/16 v1.4 Define keys (HO)
pdftexcmds.sty    2018/01/30 v0.27 Utility functions of pdfTeX for LuaTeX (HO)
   ifpdf.sty    2017/03/15 v3.2 Provides the ifpdf switch
 auxhook.sty    2016/05/16 v1.4 Hooks for auxiliary files (HO)
atbegshi.sty    2016/06/09 v1.18 At begin shipout hook (HO)
latex-xetex-bidi.def    2018/02/22 v1.3.3 bidi adaptations for `latex.ltx' for 
XeTeX engine
footnote-xetex-bidi.def    2017/08/09 v1.1 bidi footnote macros for XeTeX engin
e
article-xetex-bidi.def    2017/06/09 v0.6 bidi adaptations for standard article
 class for XeTeX engine
listings-xetex-bidi.def    2017/01/14 v1.4 bidi adaptations for listings packag
e for XeTeX engine
loadingorder-xetex-bidi.def    2017/12/29 v0.97 making sure that bidi is the la
st package loaded
cal-util.def
babel-hebrewalph.def    2010/03/02 Babel definitions for Hebrew numerals
 Adapted from hebrew.ldf (2005/03/30 v2.3h)
gloss-english.ldf    polyglossia: module for english
lstlang1.sty    2015/06/04 1.6 listings language file
 lstmisc.sty    2015/06/04 1.6 (Carsten Heinz)
 ***********

相关内容