Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I use \usepackage{marvosym} and the command \MVAt whenever I need to write the 'at' symbol (@)

But surprisingly it doesn't work in a listings environment

For example:

\begin{lstlisting}[framexleftmargin=0mm,basicstyle=\ttfamily\small,breaklines,columns=fullflexible]
' having 1=1--
' or 1 in (select @@version)--
' union all select @@version--
' OR 'unusual' = 'unusual'
' OR 'something' = 'some'+'thing'
\end{lstlisting}

Also when it comes to ttfamily\verb I have the same problem:

\begin{ttfamily}\verb|declare @s varchar(8000) select @s = db_name() if (ascii(substring(@s,|\end{ttfamily}

Is there a solution to the problem?

share|improve this question
    
Is anyone able to give me a hint? –  user1990170 Jan 26 '13 at 20:27

1 Answer 1

up vote 2 down vote accepted

You have to tell listings and \verb to change the @ into \MVAt:

\documentclass{article}
\usepackage{marvosym,listings,etoolbox}

\lstset{literate={@}{\MVAt}1}

\patchcmd{\verb}{\dospecials}{\dospecials\atspecial}{}{}
\def\atspecial{\begingroup\lccode`~=`@
  \lowercase{\endgroup\let~}\MVAt
  \catcode`@=\active}

\begin{document}
\begin{lstlisting}[framexleftmargin=0mm,
                   basicstyle=\ttfamily\small,
                   breaklines,
                   columns=fullflexible]
' having 1=1--
' or 1 in (select @@version)--
' union all select @@version--
' OR 'unusual' = 'unusual'
' OR 'something' = 'some'+'thing'
\end{lstlisting}

\verb|declare @s varchar(8000)|
\end{document}

There's no need to use \ttfamily around \verb.

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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