3

I would like to use a one-line delimiter (with [l] parameter), but without highlighting the delimiter itself; something like

sqlite> .open ex2.db

What follows sqlite> should get highlighted but not sqlite> itself. I found solutions only for multi-line delimiters. I'm not able to make them work for one-line delimiters:

enter image description here

\documentclass[a4paper,12pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[svgnames]{xcolor}
\usepackage{listings}
\usepackage{newtxtt} 

\newcommand{\functionHighlightAfterSqlite}[1]{\ttfamily\bfseries\color{red}{#1}}

\lstnewenvironment{lstSqlite}
{\lstset{
    basicstyle=\ttfamily,
    keywordstyle=\bfseries,
    language=SQL,    
    moredelim=*[l][\functionHighlightAfterSqlite]{sqlite>},
    moredelim=[l][\ttfamily\bfseries\color{red}]{...>}} } % highlights delimiter
{}

\begin{document}
\begin{lstSqlite}
sqlite> .open ex2.db
sqlite> select *
   ...> from tab;
Git|1
SQLite|3
\end{lstSqlite}
\end{document}
3

Same trick as described in this answer:

enter image description here

\documentclass[a4paper, 12pt]{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[svgnames]{xcolor}
\usepackage{listings}
\usepackage{newtxtt} 

\newcommand\styleAfterSqlitePrompt{%
    \ttfamily\bfseries\color{red}%
}

% switch to keep track of context (in a command or not)
\newif\ifcom\comfalse


\makeatletter

% This is what happens if a delimiter is encountered
\newcommand\processSqlitePrompt[1]{%
    \ifcom%                       % In this case, we're already in a command.
    \else                         % Otherwise, we just started a command;
        \global\comtrue%          % set the switch to true and
        {\lst@basicstyle #1}%     % typeset the delimiter in the basic style.
    \fi
    \styleAfterSqlitePrompt%      % In any case, apply the comment style.
}

% Reset the switch at each End-Of-Line character.
\lst@AddToHook{EOL}{\global\comfalse}

\makeatother


\lstnewenvironment{lstSqlite}{%
    \lstset{
        language     = SQL,
        basicstyle   = \ttfamily,
        keywordstyle = \bfseries,
        moredelim    = *[il][\processSqlitePrompt{sqlite>}]{sqlite>},
        moredelim    = *[il][\processSqlitePrompt{\ \ \ ...>}]{\ \ \ ...>},
    }%
}{}

\begin{document}

\begin{lstSqlite}
sqlite> .open ex2.db
sqlite> select *
   ...> from tab;
Git|1
SQLite|3
\end{lstSqlite}

\end{document}
  • Is there a way to turn on/off language settings. Like {\lst@basicstyle #1} – mwloda Dec 11 '15 at 12:09

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.