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}


  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.


%%% https://tex.stackexchange.com/questions/128103/hang-caption-in-lstlisting/128141#128141
%   \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

\usepackage{xkeyval}    % Allow to use key-value pairs in arguments of macros
\usepackage{listingsutf8}   % Use program listings
\usepackage{etoolbox}       % Utility package, mainly for packet 

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



%%%Usage \MESourceFile[keys]{source file}{caption}{label}
    \setkeys{MEMacros}{wide=false,language={[ANSI]C},options={}, decorations={},#1}% 
    % % Define the environment: a 'Program' if it might float, a simple caption if not
    \ifx\MayFloat\undefined % A kind of slides
            \vskip.2\baselineskip\color{HeadingColor}\bfseries\scriptsize #3\par\vskip\baselineskip
    \else %% Either A4 book,  WEB book or eBook
        \ifKV@MEMacros@wide %% It is a wide floating version
        \else % It is the narrow (one-column} version)
                    \setlength{\FigWidth}{\columnwidth} \else \setlength{\FigWidth}{\textwidth} \fi
    %% Start printing the figure here:
                %\mbox{}\phantomsection % for hyperrefs
                \ifx\MayFloat\undefined\else\caption{#3}\fi %\vglue-.7\baselineskip
                    \lstinputlisting[language={\ME@language}, \ME@options, label=#4, name=#4]{#2}}
                \ME@decorations % Decorating comments


        options={lastline=15, backgroundcolor=\color{yellow!10}},
        ]{HelloWorld.c}{The hello world for MWE}{lst:PrefixSumcA.c}
        options={lastline=15, backgroundcolor=\color{yellow!10}},
        ]{HelloWorld.c}{The hello world for MWE}{lst:PrefixSumcA.c}


#include <stdio.h>

int main()
    printf("hello, world\n");
  • 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.