这个问题基于以下回答的问题伊格纳西和保罗·盖斯勒。我想知道如何使用此 WinEdt QuickGuide 模板更改 Matlab-prettifier 环境中的字体。这是我的代码:
\documentclass[%
,paper=a4
,pagesize=auto
,BCOR=0.75cm
% ,oneside
,DIV=10
% ,DIV=calc
,numbers=noenddot
,captions=heading
,captions=nooneline
,listof=totoc
,bibliography=totoc
,index=totoc
,headings=normal
% ,headings=small
,USenglish,
]{scrbook}
%
\usepackage{etex}
\reserveinserts{28}
\usepackage[refsection=chapter,defernumbers=true,sorting=none,sortcites=true,autopunct=true,babel=hyphen,hyperref=true,abbreviate=false,backref=true,backend=biber]{biblatex}
\newcommand*{\VersionInformation}{%
\centering{%
Controls\par
Typeset with \LaTeXe\ and \KOMAScript\ class\par
using \textrm{Palatino} and \textsf{Bera} fonts.\par
{\scriptsize generated: \today\par}}
}
%
\usepackage[%
,headsepline
,footsepline
,plainfootsepline
]{scrpage2}
\pagestyle{scrheadings}
\setheadwidth[-7.5mm]{1.175\textwidth}
%
% headline color
\setheadsepline{.5pt}[\color{Navy}]
\setfootsepline{.5pt}[\color{Navy}]
%
\newcommand*{\ORIGchapterheadstartvskip}{}%
% 2nd save the original definition to the new command
\let\ORIGchapterheadstartvskip=\chapterheadstartvskip
% 3rd redefine the command using the saved original command
\renewcommand*{\chapterheadstartvskip}{%
\ORIGchapterheadstartvskip
{\color{Navy}%
\setlength{\parskip}{0pt}%
\noindent\rule[.3\baselineskip]{\linewidth}{1pt}\par
}%
}
% see above
\newcommand*{\ORIGchapterheadendvskip}{}%
\let\ORIGchapterheadendvskip=\chapterheadendvskip
\renewcommand*{\chapterheadendvskip}{%
{\color{Navy}%
\setlength{\parskip}{0pt}%
\noindent\rule[.3\baselineskip]{\linewidth}{1pt}\par
}%
\ORIGchapterheadendvskip
}
%
\usepackage{chapterthumb}
\renewcommand*{\chapterthumbboxcolor}{Navy}
\renewcommand*{\chapterthumbfont}{\normalfont\Large\sffamily\bfseries}
\renewcommand{\chapterthumbwidth}{.125\paperheight}
\lohead[\putchapterthumb]{\putchapterthumb}
\addtokomafont{chapterthumb}{\small{\bfseries}}
\addtokomafont{captionlabel}{\bfseries\color{Navy}}
\addtokomafont{caption}{\color{Navy}}
\addtokomafont{chapter}{\color{Navy}}
\addtokomafont{section}{\color{Navy}}
\addtokomafont{subsection}{\color{Navy}}
\addtokomafont{subsubsection}{\color{Navy}}
\addtokomafont{paragraph}{\color{Navy}}
\addtokomafont{minisec}{\color{Navy}}
\addtokomafont{pageheadfoot}{\color{Navy}}
\addtokomafont{pagefoot}{\color{Navy}}
\addtokomafont{pagenumber}{\color{Navy}}
\addtokomafont{footnoterule}{\color{Navy}}
\usepackage{marvosym}
\usepackage{%
,fix-cm
% ,fix2col
,etex
,thinsp
,xspace
% ,ifthen
,calc
}
% --------------------------------------------------------------------
%
\usepackage{babel}
%
% line break after /:
\defineshorthand{"/}{\slash}
%
\usepackage[T1]{fontenc} % EC fonts
\usepackage[utf8]{inputenc} % coding UTF-8
\usepackage[%
,showerrors%
,svgnames%
,table% colors in tables
]{xcolor}
%
% --------------------------------------------------------------------
\usepackage{%
,graphicx
,rotating
,ltablex
%
%
,dcolumn
,booktabs
}
\usepackage{siunitx}
\renewcommand{\floatpagefraction}{0.75}% Standard = 0.5
\renewcommand{\textfraction}{0.15}% Standard = 0.2
%
\renewcommand{\topfraction}{0.8}% Standard = 0.7
\setcounter{topnumber}{3} % vorher: 2
\setcounter{bottomnumber}{1} % vorher: 1
\setcounter{totalnumber}{5} % vorher: 3
%
\renewcommand{\dbltopfraction}{.8}% Standard = 0.7
\renewcommand{\dblfloatpagefraction}{.6}% Standard = 0.5
%
% --------------------------------------------------------------------
\tolerance 1414
\hbadness 1414
\emergencystretch 1.5em
\hfuzz 0.3pt
\widowpenalty = 2500
\displaywidowpenalty = 2500
\vfuzz \hfuzz
\raggedbottom
\DeclareOption{tanz}{\raggedbottom}
%
\ProcessOptions\relax
\deffootnote{2.25em}{1.75em}{\thefootnotemark.\enspace}
\usepackage{expl3,xparse}
%
\ExplSyntaxOn
%
\cs_new_eq:Nc \emph_old:n { emph~ }
\cs_new_eq:NN \emph_braces:n \textup
%
\cs_new:Npn \emph_new:n #1 {
\tl_set:Nn \l_emph_tl {#1}
\tl_replace_all:Nnn \l_emph_tl {(}{\emph_braces:n{(}}
\tl_replace_all:Nnn \l_emph_tl {)}{\emph_braces:n{)}}
\tl_replace_all:Nnn \l_emph_tl {[}{\emph_braces:n{[}}
\tl_replace_all:Nnn \l_emph_tl {]}{\emph_braces:n{]}}
\exp_args:NV \emph_old:n \l_emph_tl
}
%
\RenewDocumentCommand {\emph} {sm} {
\IfBooleanTF {#1} {\emph_old:n {#2}} {\emph_new:n {#2}}
}
%
\AtEveryCitekey{\RenewDocumentCommand{\emph}{m}{%
\emph_old:n {#1}}
}
\AtBeginBibliography{\RenewDocumentCommand{\emph}{m}{%
\emph_old:n {#1}}
}
\ExplSyntaxOff% syntax of expl3 on
\usepackage[iso]{isodate}
\PassOptionsToPackage{hyphens}{url}
\ifpdfoutput{% needs a KOMA-Script class!!!
\usepackage[%
,final
,kerning
,babel
,protrusion=true
,expansion=true % better typography, but with much larger PDF file
,tracking=true
]{microtype}
\DeclareMicrotypeSet*[tracking]{my}{ font = */*/*/sc/* }%
\SetTracking{ encoding = *, shape = sc }{ 45 }
%
\usepackage[%
,pdftex%
,plainpages=false%
,colorlinks%
,linkcolor={Navy}%
,citecolor={Navy}%
,linktocpage={true}%
,breaklinks%
,pdfcreator={pdflatex}%
,pdfstartview=FitH
,bookmarksopen=true% book marks in PDF reader
]{hyperref}
%
\usepackage{bookmark}% bookmark cleanup
}%
{%
\usepackage[%
,hypertex%
,linktocpage={true}%
,breaklinks%
]{hyperref}
%
% optimized margin alignment with microtype:
\usepackage[%
,final
,DVIoutput
,kerning
,babel
,protrusion=true
]{microtype}
}
%
\usepackage[figure]{hypcap} % links to the upper edge of floating environments
%
%% ============================================================================
% extended handling of figures
\usepackage[caption=false]{subfig}
%
%% ============================================================================
% intelligent cross references
\usepackage{cleveref}
%% ============================================================================
% Fonts
\usepackage{textcomp}
%
\linespread{1.05}\selectfont
\usepackage[scaled=.88]{beramono}
\usepackage[scaled=.86]{berasans}
\usepackage[sc,osf]{mathpazo}
\usepackage{amsmath}
%
\usepackage{fixmath}
\typearea[current]{last}
\usepackage{textcomp}
\usepackage{eurosym}
\catcode`\=13
\def{•}
%% ============================================================================
\usepackage{lscape}
\usepackage[active,new,noold,marker]{xrcs}
%% ============================================================================
\newcommand{\WinEdtCmd}[1]{\textcolor{CornflowerBlue}{\textsf{#1}}}
\newcommand{\WinEdtKey}[1]{\textcolor{LightSeaGreen}{\textsf{#1}}}
\newcommand{\WinEdtFile}[1]{\textcolor{DarkSlateGray}{\texttt{#1}}}
%========================================================================================
% Bibliography
%========================================================================================
%\addbibresource{References}% BibTeX
\defbibheading{bibempty}{}
\newcommand*{\refname}{Bibliography}
% -----------------------------------------------------------------------------
% Matlab Arguments
% -----------------------------------------------------------------------------
\definecolor{ocre}{RGB}{243,102,25}
\usepackage{filecontents}
\begin{filecontents*}{sample.m}
% create a file for output
!touch testFile.txt
fid = fopen('testFile.text', 'w')
for i=1:10
fprintf(fid,'%6.2f \n', i);
end
\end{filecontents*}
\usepackage[numbered,framed]{matlab-prettifier}
%\usepackage[font={color=ocre,bf},figurename=Fig.,labelfont={it}]{caption}
%\newfontfamily{\lstconsolas}{Consolas}
\newcommand\ph\mlplaceholder
\makeatletter
\renewcommand\phOpDelim@mlpr{$\langle$}
\renewcommand\phClDelim@mlpr{$\rangle$}
\makeatother
\renewcommand{\lstlistingname}{Matlab Algorithm}
\renewcommand{\lstlistlistingname}{List of \lstlistingname s}
\begin{document}
\KOMAoptions{cleardoublepage=plain}
\addtokomafont{caption}{\centering}
\frontmatter
\subject{\ }
\title{Controls}
\subtitle{Problem Set 1}
\author{\textsc{Author}}
\date{2015}
%
\lowertitleback{\VersionInformation}
\maketitle
\tableofcontents
\listoffigures
\lstlistoflistings
\mainmatter
\chapter{Problem 1}
\lstinputlisting[style=Matlab-editor,caption=Sample code from Matlab]{sample.m}
%\include{Chapters/Solution1}
\begin{lstlisting}[
style=Matlab-editor,
basicstyle=\mlttfamily,
escapechar=`,
caption={For educational purposes},
]
% example of while loop using placeholders
while `\ph{condition}`
if `\ph{something-bad-happens}`
break
else
x = 2015 + 10098 % do something useful
end
% do more things
end
\end{lstlisting}
%% ============================================================================
\backmatter
\lohead[]{}
\printbibheading[heading=bibintoc,title=\bibname]
\printbibliography[heading=subbibintoc,type=book,prefixnumbers={B},title={Books}]
\printbibliography[heading=subbibintoc,type=article,prefixnumbers={A},title={Articles}]
\printbibliography[heading=subbibintoc,type=online,prefixnumbers={O},title={Online}]
\end{document}
然而,当我尝试实现
\usepackage[font={color=ocre,bf},figurename=Fig.,labelfont={it}]{caption} \newfontfamily{\lstconsolas}{Consolas}
使用 PDF latex 时出现错误。 伊格纳西说我不能使用这种格式的 PDFLaTeX。我该如何更改这里的 Matlab 字体?
答案1
请注意,由于您发布的代码无法编译且依赖于非标准包,因此无法按原样使用它。当我尝试编译它时,我得到了无数的编译错误。当我修复这些错误时,我收到了有关缺少软件包的投诉。当我删除这些软件包时,又出现了更多错误。
你想要这样的东西吗?
据我所知,您之前问题的答案已经解释了如何做到这一点。
这是产生上述输出的代码的最小化版本:
\documentclass[paper=a4,pagesize=auto,BCOR=0.75cm,DIV=10,numbers=noenddot,captions=heading,captions=nooneline,listof=totoc,bibliography=totoc,index=totoc,headings=normal,USenglish]{scrbook}
\usepackage{babel}
% line break after /:
\defineshorthand{"/}{\slash}
\usepackage[T1]{fontenc} % EC fonts
\usepackage[utf8]{inputenc} % coding UTF-8
\usepackage[showerrors,svgnames,table]{xcolor}
\definecolor{ocre}{RGB}{243,102,25}
% Fonts
\linespread{1.05}\selectfont
% \usepackage[scaled=.88]{beramono}
\usepackage{inconsolata}% use Inconsolata as typewriter font
\usepackage[scaled=.86]{berasans}
\usepackage[sc,osf]{mathpazo}
\usepackage{amsmath}
\usepackage{fixmath}
% -----------------------------------------------------------------------------
% Matlab Arguments
% -----------------------------------------------------------------------------
\definecolor{ocre}{RGB}{243,102,25}
\usepackage{filecontents}
\begin{filecontents*}{sample.m}
% create a file for output
!touch testFile.txt
fid = fopen('testFile.text', 'w')
for i=1:10
fprintf(fid,'%6.2f \n', i);
end
\end{filecontents*}
\usepackage[numbered,framed]{matlab-prettifier}
\usepackage[font={color=ocre,bf},figurename=Fig.,labelfont={it}]{caption}
\newcommand\ph\mlplaceholder
\makeatletter
\renewcommand\phOpDelim@mlpr{$\langle$}
\renewcommand\phClDelim@mlpr{$\rangle$}
\makeatother
\renewcommand{\lstlistingname}{Matlab Algorithm}
\begin{document}
\addtokomafont{caption}{\centering}
\lstinputlisting[style=Matlab-editor,caption=Sample code from Matlab]{sample.m}
\begin{lstlisting}[
style=Matlab-editor,
basicstyle=\mlttfamily,
escapechar=`,
caption={For educational purposes},
]
% example of while loop using placeholders
while `\ph{condition}`
if `\ph{something-bad-happens}`
break
else
x = 2015 + 10098 % do something useful
end
% do more things
end
\end{lstlisting}
\end{document}