0

I have a major and some minor problems with the MWE below.

The major one: when I uncomment \usepackage{beamerarticle}, my macro definition starts to contain some extra '}', probably some macro expansion mistake.

The minor ones:

  1. What I would like to see, is "0.1 Programlista", and "Programlista 0.1" is displayed as caption
  2. When I uncomment \usepackage{caption}, the name I give in

    \floatname{program}{\ifx\LectureLanguage\undefined Program lista\else Listing\fi}

disappears.

  1. I liked the style shown in Hang caption in lstlisting, but for some reason, in my MWE seems not to work

  2. A sidenote to the WEBsite: the marking as "code" automates itself, i.e. sometimes disappears, sometimes formatting remains, but the gray background disappears. In this question I attempted formatting the MWE a couple of times, with no success.


\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");
}
2
  • As a C-Programmer I have to punish you for the incomplete main specification ;-) – user31729 Jun 7 '15 at 8:38
  • @Christian Hupfer I agree, but presently I want just to print the code, rather than execute it. ;-) But anyhow, I wanted to be proud of one of my great programs. (some people missed in my previous post the "hello.c" source.) – katang Jun 9 '15 at 11:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.