使用 matlab-prettifier 描述的帶有 \mlttfamily 的 Bera Mono 字體

使用 matlab-prettifier 描述的帶有 \mlttfamily 的 Bera Mono 字體

我正在將 Latex 與 pdftex 一起使用,並嘗試將 Bera Mono 字體與文件\mlttfamily描述的一起使用matlab-prettifier。但是,我產生的輸出接縫忽略我的\lstset basicstyle = \mlttfamily設定並使用預設設定\ttfamily?下面是我的輸出影像。

\documentclass[border=30pt]{standalone} 

\usepackage[final]{matlab-prettifier}

\usepackage[T1]{fontenc}

\lstset{
  style              = Matlab-editor,
  basicstyle         = \mlttfamily, %\ttfamily
  escapechar         = ",
  mlshowsectionrules = true,
}

\begin{document}

\begin{lstlisting}[style=Matlab-editor]
%% Code sections are highlighted.
% System command are supported...
!gzip sample.m
% ... as is line continuation.
A = [1, 2, 3,... % (mimicking the ouput is good)
 4, 5, 6]
fid = fopen('testFile.text', 'w')
for i=1:10
  fprintf(fid,'%6.2f \n', i);
end
x=1; %% this is just a comment, though
% Context-sensitive keywords get highlighted correctly...
p = properties(mydate); %(here, properties is a function)
x = linspace(0,1,101);
y = x(end:-1:1)
% ... even in nonsensical code.
]end()()(((end end)end ))))end (function end
%{
    block comments are supported
%} even
runaway block comments
are
   \end{lstlisting}

\end{document}

輸出影像

答案1

這解決了問題,\lstset定義了預設設置,\lstlisting並且我之前覆蓋了此樣式設置,而沒有更改字體。
以下程式碼現在可以正確地將字體變更為 Bera Mono。

\documentclass[border=30pt]{standalone} 

\usepackage[final]{matlab-prettifier}

\usepackage[T1]{fontenc}

\lstset{
  style              = Matlab-editor,
  basicstyle         = \mlttfamily, %\ttfamily
  escapechar         = ",
  mlshowsectionrules = true,
}

\begin{document}

\begin{lstlisting}
%% Code sections are highlighted.
% System command are supported...
!gzip sample.m
% ... as is line continuation.
A = [1, 2, 3,... % (mimicking the ouput is good)
     4, 5, 6]
fid = fopen('testFile.text', 'w')
for i=1:10
  fprintf(fid,'%6.2f \n', i);
end
x=1; %% this is just a comment, though
% Context-sensitive keywords get highlighted correctly...
p = properties(mydate); %(here, properties is a function)
x = linspace(0,1,101);
y = x(end:-1:1)
% ... even in nonsensical code.
]end()()(((end end)end ))))end (function end
%{
    block comments are supported
%} even
runaway block comments
are
\end{lstlisting}

\end{document}

答案2

我現在從 matlab-prettier 的概述中看到以下內容有效。

            \documentclass[border=30pt]{standalone} 

            \usepackage[final]{matlab-prettifier}

            \usepackage[T1]{fontenc}

            \begin{document}

            \begin{lstlisting}[
              style      = Matlab-editor,
              basicstyle = \mlttfamily,
            ]

            %% Code sections are highlighted.
            % System command are supported...
            !gzip sample.m
            % ... as is line continuation.
            A = [1, 2, 3,... % (mimicking the ouput is good)
                 4, 5, 6]
            fid = fopen('testFile.text', 'w')
            for i=1:10
              fprintf(fid,'%6.2f \n', i);
            end
            x=1; %% this is just a comment, though
            % Context-sensitive keywords get highlighted correctly...
            p = properties(mydate); %(here, properties is a function)
            x = linspace(0,1,101);
            y = x(end:-1:1)
            % ... even in nonsensical code.
            ]end()()(((end end)end ))))end (function end
            %{
                block comments are supported
            %} even
            runaway block comments
            are

            \end{lstlisting}

            \end{document}

輸出

相關內容