3

Using listing a custom language is defined and auto indentation is defined. The MWE does not do the indentation

\documentclass{book}

\usepackage[formats]{listings}
\usepackage{xcolor}

% Define Language
\lstdefinelanguage{sofl}
{
    breaklines=true,
    tabsize=2,
    sensitive=false, % keywords are not case-sensitive
    morecomment=[l]{//}, % l is for line comment
    morecomment=[s]{/*}{*/}, % s is for start and end delimiter
    morestring=[b]", % defines that strings are enclosed in double quotes
    morekeywords={begin,end}
}
\lstdefineformat{sofl}%
{%
    \{=\newline\string\newline\indent,%
    \}=[;]\newline\noindent\string\newline,%
    \};=\newline\noindent\string\newline,%
    ;=[\ ]\string\space
}%
\lstnewenvironment{sofl} {
    \lstset{format=sofl}
    \lstset{language=sofl}
} {}

\begin{document}

\begin{sofl}
flow_b ->   
begin
if
flow_e = False;
f(data_b) ->
begin           
flow_d = True; 
data_d = data_b;
end
not f(data_b) ->
begin           
flow_d = True; 
data_d = data_b;
end
fo
end
\end{sofl}
\end{document}

When updating the example to use this fragment

\lstdefineformat{sofl}%
{%
    begin=\newline\string\newline\indent,%
    end=[;]\newline\noindent\string\newline,%
    end;=\newline\noindent\string\newline,%
    ;=[\ ]\string\space
}%

the compiler give the error Extra \fi. \begin{sofl}.

  • It seems such constructs need to start with a character of class other cf. the standard character table in the listings documentation – Andrew Swann Nov 28 '18 at 11:19

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.