# Using lstlistings environment inside of an \fbox

I have a function being used in my document:

\documentclass{article}
% Change "article" to "report" to get rid of page number on title page
\usepackage{amsmath,amsfonts,amsthm,amssymb}
\usepackage{setspace}
\usepackage{Tabbing}
\usepackage{listings}
\usepackage{fancyhdr}
\usepackage{lastpage}
\usepackage{caption}
\usepackage{epstopdf}
\usepackage{Pgfplots}
\usepackage[]{mcode}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usepackage{extramarks}
\usepackage{chngpage}
\usepackage{soul,color}
\usepackage{graphicx,float,wrapfig}

% In case you need to adjust margins:
\topmargin=-0.45in      %
\evensidemargin=0in     %
\oddsidemargin=0in      %
\textwidth=6.5in        %
\textheight=9.0in       %

{% We put this space here to make sure we're disconnected from the previous
% passage

\noindent\fbox{\begin{minipage}[c]{\columnwidth}#1\end{minipage}}%
\marginpar{\fbox{\homeworkSectionName}}%

% We put the blank space above in order to make sure this
% \marginpar gets correctly placed.
}%


I then later use (I just want to add a few lines of MATLAB code, so notice the package mcode is used):

\sectionAnswer{
\begin{lstlisting}
a = 1;
b = 2;
c = a^2 + b^2;
\end{lstlisting}
}


I am aware that this is because listings (including verbatim content) cannot be passed as arguments to other functions/macros... So I am looking for a workaround? Ideally, I don't want to modify the original macro, because it works quite well, really. So, if I do modify it, \fbox would need to be replaced by something with identical properties.

Following advice from Werner, the macro is now:

\newcommand{\sectionAnswer}[1]
{% We put this space here to make sure we're disconnected from the previous
% passage

\noindent\fbox{\begin{minipage}[c]{\dimexpr\linewidth-2\fboxsep-2\fboxrule}#1\end{minipage}}
% modify page width from \columnwidth to \dimexpr\linewidth-2\fboxsep-2\fboxrule
\marginpar{\fbox{\homeworkSectionName}}%

% We put the blank space above in order to make sure this
% \marginpar gets correctly placed.
}%


I should also note, that this is a modified template, based off Ted Pavlic's.

If you wish to maintain the current setup, then you can store the lstlisting inside a box before passing it to \sectionAnswer:

\newsavebox{\codebox}% For storing code in a box

\begin{lrbox}{\codebox}
\begin{lstlisting}
a = 1;
b = 2;
c = a^2 + b^2;
\end{lstlisting}
\end{lrbox}


Note that your minipage width is probably better set as \dimexpr\linewidth-2\fboxsep-2\fboxrule.