![패키지 목록의 여러 줄 Matlab 주석](https://rvso.com/image/335504/%ED%8C%A8%ED%82%A4%EC%A7%80%20%EB%AA%A9%EB%A1%9D%EC%9D%98%20%EC%97%AC%EB%9F%AC%20%EC%A4%84%20Matlab%20%EC%A3%BC%EC%84%9D.png)
내 보고서에 일부 Matlab 코드를 포함하기 위해 패키지 목록을 사용하고 있습니다. 다음으로 시작하는 주석에서는 잘 작동 %
하지만 여러 줄 주석은 인식하지 못합니다 %{ ... %}
.
\usepackage{listings}
\lstset{language=Matlab}
...
\begin{lstlisting}
% normal comment
MATLAB code
%{
This is
a multiline
comment
%}
function [x,y] = test(x)
\end{lstlisting}
준다
대신에
Matlab에서.
\lstset
작동하게 하려면 어떻게 변경해야 합니까 ?
답변1
내 추천은 패키지를 사용하는 것입니다matlab-prettifier
이는 언어 정의(블록 주석 지원 포함) listings
에서 제공하는 것 이상으로 ' MATLAB 코드에 대한 향상된 기능을 제공합니다 .listings
Matlab
\documentclass{article}
\usepackage{matlab-prettifier}
\lstset{style=Matlab-editor}
\begin{document}
\begin{lstlisting}
% normal comment
MATLAB code
%{
This is
a multiline
comment
%}
function [x,y] = test(x)
\end{lstlisting}
\end{document}
listings
어떤 이유로 인해 기존 언어 구현과 함께 사용해야 하는 경우 Matlab
패키지 morecomment
키를 설정하여 블록 주석에 대한 지원을 추가할 수 있습니다.
morecomment=[s]{\%\{}{\%\}}
여기서는 [s]
두 개의 구분 기호를 찾고 있음을 의미합니다. 첫 번째는 블록 주석을 열고 두 번째는 닫습니다. 다음 중괄호 그룹에는 각각 블록 주석의 여는 구분 기호와 닫는 구분 기호가 포함되어 있습니다. 주석 구분 기호를 정의할 때 백분율 기호와 개별 열기/닫기 중괄호는 모두 백슬래시로 이스케이프되어야 합니다.
\documentclass{article}
\usepackage{listings}
\lstset{
language=Matlab,
basicstyle=\ttfamily,
morecomment=[s]{\%\{}{\%\}},
}
\begin{document}
\begin{lstlisting}
% normal comment
MATLAB code
%{
This is
a multiline
comment
%}
function [x,y] = test(x)
\end{lstlisting}
\end{document}