I have tried to minimise my scenario here. Basically, I would like to call each piece of highlighted code from external tex file over the beamer class.
There are two .tex files
- code.tex
- main.tex
My aim is to store codes inside code.tex and call them inside main.tex based on the title in order to tidy up everything. If I call \testCode{} on the main.tex, there are various issues. Any idea how I can handle this process ?
code.tex
\def\testCode{
\begin{lstlisting}[style=CStyle]
#include <stdio.h>
int main(void)
{
printf("Hello World!");
}
\end{lstlisting}
}
\def\testText{
Test input text
}
main.tex
\documentclass{beamer}
\mode<presentation>
{
\usetheme{Madrid} % or try Darmstadt, Madrid, Warsaw, ...
\usecolortheme{beaver} % or try albatross, beaver, crane, ...
\usefonttheme{serif} % or try serif, structurebold, ...
\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{caption}[numbered]
}
\usepackage{xcolor}
\usepackage{listings}
\definecolor{mGreen}{rgb}{0,0.6,0}
\definecolor{mGray}{rgb}{0.5,0.5,0.5}
\definecolor{mPurple}{rgb}{0.58,0,0.82}
\definecolor{backgroundColour}{rgb}{0.95,0.95,0.92}
\lstdefinestyle{CStyle}{
backgroundcolor=\color{backgroundColour},
commentstyle=\color{mGreen},
keywordstyle=\color{magenta},
numberstyle=\tiny\color{mGray},
stringstyle=\color{mPurple},
basicstyle=\footnotesize,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
numbers=left,
numbersep=5pt,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=2,
language=C
}
\input{code.tex}
\begin{document}
\begin{frame}{title here}
\testText{}
\testCode{}
\end{frame}
\end{document}
