让音乐角色在 LyX 中发挥作用

让音乐角色在 LyX 中发挥作用

我在 LyX 中编写的文档中有三个字符会产生问题:♯、♭ 和 ♮。它们在程序列表中的用法如下: 在此处输入图片描述

并产生此错误:

在此处输入图片描述

当我允许非 TeX 字体时,出现以下错误:

在此处输入图片描述

我是 LyX 和 Tex 的完全初学者。这里合适的解决方案是什么?

以下是导致错误的一个最小示例:

#LyX 2.2 created this file. For more info see http://www.lyx.org/
\lyxformat 508
\begin_document
\begin_header
\save_transient_properties true
\origin unavailable
\textclass scrbook
\use_default_options true
\maintain_unincluded_children false
\language english
\language_package default
\inputencoding auto
\fontencoding global
\font_roman "default" "default"
\font_sans "default" "default"
\font_typewriter "default" "default"
\font_math "auto" "auto"
\font_default_family default
\use_non_tex_fonts false
\font_sc false
\font_osf false
\font_sf_scale 100 100
\font_tt_scale 100 100
\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
\index Index
\shortcut idx
\color #008000
\end_index
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\paragraph_indentation default
\quotes_language english
\papercolumns 1
\papersides 1
\paperpagestyle default
\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
The charachters outside a program listing seem to be fine:
\end_layout

\begin_layout Standard
\end_layout

\begin_layout Standard
\end_layout

\begin_layout Standard
\end_layout

\begin_layout Standard
But in the program listing they don't work:
\end_layout

\begin_layout Standard
\begin_inset listings
inline false
status open

\begin_layout Plain Layout

  public String symbol() {
\end_layout

\begin_layout Plain Layout

    switch (this) {
\end_layout

\begin_layout Plain Layout

      case Sharp:
\end_layout

\begin_layout Plain Layout

        return "♯";
\end_layout

\begin_layout Plain Layout

      case Flat:
\end_layout

\begin_layout Plain Layout

        return "♭";
\end_layout

\begin_layout Plain Layout

      case Natural:
\end_layout

\begin_layout Plain Layout

        return "♮";
\end_layout

\begin_layout Plain Layout

      case None:
\end_layout

\begin_layout Plain Layout

      default:
\end_layout

\begin_layout Plain Layout

        return "";
\end_layout

\begin_layout Plain Layout

    }
\end_layout

\begin_layout Plain Layout

  }
\end_layout

\end_inset


\end_layout

\end_body
\end_document

答案1

该解决方案基于解决方案这里

在 LyX 中,首先转到“文档”>“设置”>“列表”,然后输入以下行:

escapeinside={\%*}{*)}

然后在 LyX 中,转到“查看”>“源”。底部会弹出一个面板,显示 LyX 将导出的 LaTeX 代码(请记住,LyX 首先通过导出到 LaTeX 来创建 PDF)。在 LyX 的主文本区域中,将光标放在 ♯ 旁边。在源预览中,它将显示

\ensuremath{\sharp}

复制它并将其放在我们在第一步中定义的转义标记之间。对其他的也执行相同的操作。

最终的文档如下:

#LyX 2.2 created this file. For more info see http://www.lyx.org/
\lyxformat 508
\begin_document
\begin_header
\save_transient_properties true
\origin unavailable
\textclass scrbook
\use_default_options true
\maintain_unincluded_children false
\language english
\language_package default
\inputencoding auto
\fontencoding global
\font_roman "default" "default"
\font_sans "default" "default"
\font_typewriter "default" "default"
\font_math "auto" "auto"
\font_default_family default
\use_non_tex_fonts false
\font_sc false
\font_osf false
\font_sf_scale 100 100
\font_tt_scale 100 100
\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
\index Index
\shortcut idx
\color #008000
\end_index
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\paragraph_indentation default
\quotes_language english
\papercolumns 1
\papersides 1
\paperpagestyle default
\listings_params "escapeinside={\%*}{*)}"
\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
The charachters outside a program listing seem to be fine:
\end_layout

\begin_layout Standard
\end_layout

\begin_layout Standard
\end_layout

\begin_layout Standard
\end_layout

\begin_layout Standard
But in the program listing they don't work:
\end_layout

\begin_layout Standard
\begin_inset listings
inline false
status open

\begin_layout Plain Layout

  public String symbol() {
\end_layout

\begin_layout Plain Layout

    switch (this) {
\end_layout

\begin_layout Plain Layout

      case Sharp:
\end_layout

\begin_layout Plain Layout

        return "%*
\backslash
ensuremath{
\backslash
sharp}*)";
\end_layout

\begin_layout Plain Layout

      case Flat:
\end_layout

\begin_layout Plain Layout

        return "%*
\backslash
ensuremath{
\backslash
flat}*)";
\end_layout

\begin_layout Plain Layout

      case Natural:
\end_layout

\begin_layout Plain Layout

        return "%*
\backslash
ensuremath{
\backslash
natural}*)";
\end_layout

\begin_layout Plain Layout

      case None:
\end_layout

\begin_layout Plain Layout

      default:
\end_layout

\begin_layout Plain Layout

        return "";
\end_layout

\begin_layout Plain Layout

    }
\end_layout

\begin_layout Plain Layout

  }
\end_layout

\end_inset


\end_layout

\end_body
\end_document

最终的 PDF 如下:

在此处输入图片描述

答案2

这个答案使用非 TeX 字体和 XeTeX:

转到“文档”>“设置”>“字体”,然后单击“使用非 TeX 字体”。我选择了 FreeSans 字体,这在我的操作系统 Ubuntu 上很常见:

在此处输入图片描述

保存,然后使用 XeTeX 查看。我得到以下 PDF:

在此处输入图片描述

您也可以使用 LuaTeX,但根据您的 TeX Live 安装,您可能需要添加\usepackage{luatex85}到文档 > 设置 > 前言。

相关内容