我对下面的 MWE 有一个主要问题和一些小问题。
主要的问题:当我取消注释时\usepackage{beamerarticle}
,我的宏定义开始包含一些额外的'}',可能是一些宏扩展错误。
次要的:
- 我希望看到的是“0.1 Programlista”,并且“Programlista 0.1”显示为标题
当我取消注释时
\usepackage{caption}
,我给出的名字\floatname{program}{\ifx\LectureLanguage\undefined Program lista\else Listing\fi}
消失。
我喜欢在列表中悬挂标题,但出于某种原因,在我的 MWE 中似乎不起作用
网站上的附注:标记为“代码”会自动显示,即有时会消失,有时格式保留,但灰色背景会消失。在这个问题上,我尝试格式化 MWE 几次,但没有成功。
\documentclass{memoir}
%\usepackage{beamerarticle}
%\usepackage{caption}
%%% https://tex.stackexchange.com/questions/128103/hang-caption-in-lstlisting/128141#128141
%\DeclareCaptionFont{white}{\color{white}}
%\DeclareCaptionFormat{listing}{%
% \makebox[\linewidth][l]{\colorbox[cmyk]{0.43, 0.35, 0.35,0.01}{%
% \setbox0=\hbox{#1#2}%
% \begin{minipage}{\textwidth}
% \hangindent\wd0\strut#1#2#3\leavevmode
% \end{minipage}}%
% }%
% }
% \captionsetup[lstlisting]{format=listing,labelfont=white,textfont=white, singlelinecheck=false, margin=0pt, font={bf,footnotesize}}
\def\LecturePrintable{Book} % It is a kind of printable format
\def\MayFloat{YES} % Some environments are allowed to float
%\def\lstsize{\scriptsize}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{xkeyval} % Allow to use key-value pairs in arguments of macros
\usepackage{listingsutf8} % Use program listings
\usepackage{etoolbox} % Utility package, mainly for packet
\usepackage{adjustbox}
\ifx\MayFloat\undefined
\else
\usepackage{float}
\floatstyle{plaintop}
\newfloat{program}{thp}{lpp}[chapter]
\floatname{program}{\ifx\LectureLanguage\undefined Program lista\else Listing\fi}
\fi
\usepackage[english,magyar]{babel}
\makeatletter
\define@key{MEMacros}{color}{\def\ME@color{#1}}
\define@key{MEMacros}{decorations}{\def\ME@decorations{#1}}
\define@key{MEMacros}{language}{\def\ME@language{#1}}
\define@key{MEMacros}{options}{\def\ME@options{#1}}
\define@boolkey{MEMacros}{wide}[true]{}
\newlength{\FigWidth}
\makeatletter
%%%Usage \MESourceFile[keys]{source file}{caption}{label}
\newcommand\MESourceFileNew[4][]{
\setkeys{MEMacros}{wide=false,language={[ANSI]C},options={}, decorations={},#1}%
% % Define the environment: a 'Program' if it might float, a simple caption if not
\lstset{language=C,keywordstyle=\bfseries\color{magenta}}
\ifx\MayFloat\undefined % A kind of slides
\def\startsource{
\setlength{\FigWidth}{\textwidth}
\vskip.2\baselineskip\color{HeadingColor}\bfseries\scriptsize #3\par\vskip\baselineskip
}
\def\stopsource{}
\else %% Either A4 book, WEB book or eBook
\ifKV@MEMacros@wide %% It is a wide floating version
\def\startsource{
\setlength{\FigWidth}{.7\textwidth}
\begin{program*}[h!btp]
}
\def\stopsource{\end{program*}}
\else % It is the narrow (one-column} version)
\if@twocolumn
\setlength{\FigWidth}{\columnwidth} \else \setlength{\FigWidth}{\textwidth} \fi
\def\startsource{
\begin{program}[h!btp]
}
\def\stopsource{\end{program}}
\fi
\fi
%% Start printing the figure here:
\startsource
\maxsizebox{\FigWidth}{.5\textheight}
{
%\mbox{}\phantomsection % for hyperrefs
\ifx\MayFloat\undefined\else\caption{#3}\fi %\vglue-.7\baselineskip
\begingroup\protected@edef\x{\endgroup\noexpand
\lstinputlisting[language={\ME@language}, \ME@options, label=#4, name=#4]{#2}}
\x
\ME@decorations % Decorating comments
}
\stopsource
}
\makeatother
\usepackage{tikz}
\begin{document}
\twocolumn
\MESourceFileNew[
options={lastline=15, backgroundcolor=\color{yellow!10}},
]{HelloWorld.c}{The hello world for MWE}{lst:PrefixSumcA.c}
\MESourceFileNew[wide,
options={lastline=15, backgroundcolor=\color{yellow!10}},
]{HelloWorld.c}{The hello world for MWE}{lst:PrefixSumcA.c}
\end{document}
#include <stdio.h>
int main()
{
printf("hello, world\n");
}