我正在使用该listings
包插入我为需要撰写的一些论文创建的 MatLab 例程。除了符号%
(MatLab 中的注释)与下一个字符重叠外,一切都运行良好。下面是一张显示此现象的图像。
显示该问题的 MWE 如下:
\documentclass[letterpaper,12pt,openany,final]{memoir}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{graphicx} %Gráficos
\usepackage[top=4cm,right=2.5cm,left=3cm, bottom=3cm]{geometry}
\usepackage{ucs}
\usepackage{xcolor}
\usepackage{color,calc,graphicx,soul}
\usepackage{float}
\usepackage{rotating}
\usepackage{parskip}
\usepackage{mathptmx}%Fuente
\usepackage{epstopdf}
\setlength{\evensidemargin}{\oddsidemargin}
\title{Lorem Ipsum}
\author{DOlor Sit amet}
\usepackage{textcomp}
\usepackage{listingsutf8}
\renewcommand\lstlistingname{Código}
\renewcommand\lstlistlistingname{Índice de Códigos Fuente}
\lstset{
backgroundcolor=\color{white},
tabsize=4,
rulecolor=,
literate={ó}{{\'o}}1
{á}{{\'a}}1
{é}{{\'e}}1
{º}{{\textdegree}}1
{ú}{{\'u}}1,
escapeinside={\%*}{*)},
language=octave,
basicstyle=\scriptsize,
numberstyle=\tiny,
upquote=true,
aboveskip={1.5\baselineskip},
columns=fixed,
showstringspaces=false,
extendedchars=true,
breaklines=true,
prebreak = \raisebox{0ex}[0ex][0ex]{\ensuremath{\hookleftarrow}},
frame=single,
showtabs=false,
name=Feedservoplot
showspaces=false,
texcl=false,
inputencoding=latin1,
numbers=left,
firstnumber=auto,
showstringspaces=false,
identifierstyle=\ttfamily,
keywordstyle=\color[rgb]{0,0,1},
commentstyle=\color[rgb]{0.133,0.545,0.133},
stringstyle=\color[rgb]{0.627,0.126,0.941},
escapeinside={(*@}{@*)}
}
\usepackage[protrusion=true,expansion=true]{microtype} %Alineado óptico
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage[activeacute,spanish] {babel}
\renewcommand\shorthandsspanish{}
\renewcommand{\arraystretch}{1.2}
\clubpenalty=10000
\widowpenalty=10000
\setcounter{tocdepth}{2}
\setcounter{secnumdepth}{2}
\setcounter{lofdepth}{2}
\usepackage[]{hyperref}
\usepackage{memhfixc}
\begin{document}
\setcounter{chapter}{1}
\setlength{\evensidemargin}{\oddsidemargin}
\chapter{Lorem ipsum}
Lorem ipsum dolor sit amet:
\begin{lstlisting}
a%
\end{lstlisting}
\begin{equation}
\frac{d}{dt} \frac{\partial \mathcal{L}}{\partial \dot{q_i}}
\end{equation}
\begin{equation}
a<0
\end{equation}
\end{document}
有什么建议吗?提前致谢。
此致,
查理
附言:我必须说我不知道这是否发生在其他程序语言中。
答案1
spanish
问题来自于与模块的不良交互babel
,如下面的 MWE 所示:
\documentclass{memoir}
\usepackage[spanish]{babel}
\usepackage{listingsutf8}
\spanishplainpercent
\begin{document}
\begin{lstlisting}
%A
%a
%b
\end{lstlisting}
\end{document}
该spanish
模块对百分比符号进行了特殊处理,产生了不理想的结果。使用\spanishplainpercent
可解决问题:
\documentclass{memoir}
\usepackage[spanish]{babel}
\usepackage{listingsutf8}
\spanishplainpercent
\begin{document}
\begin{lstlisting}
%A
%a
%b
\end{lstlisting}
\end{document}
如果您想要在文档的其他部分保留模块为百分比符号引入的精细空间,您可以执行以下操作:
\documentclass{memoir}
\usepackage[spanish]{babel}
\usepackage{listingsutf8}
\makeatletter
\def\spanishplainpercent{\let\es@sppercent\@empty}
\def\spanishpercent{\def\es@sppercent{\unskip\textormath{$\m@th\,$}{\,}}}
\makeatother
\begin{document}
8\%
\spanishplainpercent 8\%
\begin{lstlisting}
%A
%a
%b
\end{lstlisting}
\spanishpercent
8\%
\end{document}
\spanishplainpercent
停用精细空间(并解决列表问题)并\spanishpercent
激活空间。
这可以使用包自动完成etoolbox
:
\usepackage{etoolbox}
\makeatletter
\def\spanishplainpercent{\let\es@sppercent\@empty}
\def\spanishpercent{\def\es@sppercent{\unskip\textormath{$\m@th\,$}{\,}}}
\makeatother
\AtBeginEnvironment{lstlisting}{\spanishplainpercent}
\AtEndEnvironment{lstlistings}{\spanishpercent}