0

I am quite new to LaTeX and recently started learning tikz. I use 'showexpl' and 'listings' package to generate examples of tikz codes and their outputs in overleaf. Almost all of my files preamble are too large. So, I create several packages (.sty files) with each containing small parts of my preamble and then I put all of them of in the main file inside a single usepackage. But, when doing this with with showexpl I get an error 'undefined control sequence'.Although the file(main.tex) compiles fine without any issue but still it produces error. How can I get get rid of the errors? Here is the link of my source code:
https://www.overleaf.com/read/nwkdqyrmdcvf https://www.overleaf.com/8629643923mmtjtdbfmrfs

EDIT-1: As stated in comment, I have tried my best to post here the MWE, although it is quite large and messy since I have to gather several pieces of code from several files and put them together,so it became scattered

\documentclass[11pt]{book}
\usepackage[dvipsnames,svgnames,x11names]{xcolor}
\usepackage[all]{tcolorbox}
\usepackage{showexpl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
%==================================={geometry}
\usepackage{geometry}
\geometry{total={18cm,25cm},left=2cm}
%==================================={other}
\usepackage{tikz}
\usepackage{listings,keyval}
\lstloadlanguages{[AspectJ]java,[AlLaTeX]TeX,[ANSI]C,}
\lstloadaspects{keywordcomments,procnames,hyper,formats}
%==================================={lstnewenvironment}
\lstnewenvironment{code}[1][]
{\lstset{style=mystyle,language={[PTX2]ProTeX}}}{}
\lstMakeShortInline[style=mystyle,language={[PTX]ProTeX}]!
%==================================={lstdefinelanguage}
\lstdefinelanguage[PTX]{ProTeX}
{language=[AlLaTeX]TeX,
basicstyle=\ttfamily\color{black},
moredelim=**[l][\color{blue}]{\\},
moredelim=**[s][\color{SpringGreen3}]{[}{]},
moredelim=**[s][\color{SpringGreen3}]{[<}{>]},
moredelim=**[s][\color{red}]{\{}{\}},
moredelim=**[s][\color{red}]{\{<}{>\}},
moredelim=**[s][\color{Turquoise2}]{<}{>}}
%==================================={lstdefinelanguage-2}
\lstdefinelanguage[PTX2]{ProTeX}
{language=[AlLaTeX]TeX,
basicstyle=\ttfamily\color{black},
morekeywords={lstloadlanguages,lstloadaspects,lstset,lstalias,lstdefinelanguage,lstdefinestyle,lstdefineformat,lstnewenvironment,
lstMakeShortInline},
keywordstyle=\color{red}\bfseries,
moretexcs={color,lstlistoflistings,thelstlisting},
texcsstyle=*\color{blue}\bfseries,
commentstyle=\color{SpringGreen4}\itshape,
}
%==================================={lstdefinestyle}
\lstdefinestyle{mystyle}
%...................................(Line numbers)
{numbers=left,
numberfirstline=true,
numberstyle=\bfseries\scriptsize\color{black},
numbersep=10pt,
firstnumber=auto,
%...................................(frame-shape)
frame=single,
frame=TBRL,
framesep=0pt,
rulesep=2pt,
framerule=0pt,
xleftmargin=1cm,
framexleftmargin=1cm,
framextopmargin=10pt,
framexbottommargin=10pt,
%...................................(frame-color)
backgroundcolor=\color{black!2},
rulecolor=\color{white},
fillcolor=\color{black!2},
rulesepcolor=\color{blue},
escapeinside={?}{?},
%...................................(others)
breaklines=true,
breakindent=0pt}
%==================================={lstdefinestyle-2}
\lstdefinestyle{explstyle}
%...................................(Line numbers)
{numbers=left,
numberfirstline=true,
numberstyle=\bfseries\scriptsize\color{black},
numbersep=10pt,
firstnumber=auto,
%...................................(frame-shape)
frame=single,
frame=TBRL,
framesep=0pt,
rulesep=2pt,
framerule=0pt,
xleftmargin=1cm,
framexleftmargin=1cm,
framextopmargin=10pt,
framexbottommargin=10pt,
%...................................(frame-color)
backgroundcolor=\color{SpringGreen4!5},
rulecolor=\color{SpringGreen4!5},
fillcolor=\color{SpringGreen4!5},
rulesepcolor=\color{SpringGreen4!5},
escapeinside={?}{?},
%...................................(others)
breaklines=true,
breakindent=0pt}
\newtcolorbox{box2}
{colback=SpringGreen4!5,colframe=SpringGreen4,fonttitle=\bfseries}
\newtcbox{\minibox}[2][]
{colback=red!5,colframe=red,fonttitle=\bfseries,title={#2}#1}
\lstset{explpreset={style=mystyle,language={[PTX2]ProTeX}}}
\renewcommand\ResultBox{\fcolorbox{green}{Snow1}}
\setlength\ResultBoxSep{10pt}
\setlength\ResultBoxRule{2pt}
\begin{document}
\lstset{explpreset={style=explstyle,language={[PTX2]ProTeX}}}
\begin{box2}
\begin{LTXexample}[pos=r,justification=\centering]
\begin{document}
!Hello World!
\end{document}
\end{LTXexample}
\end{box2}
\end{document}

Note:In the code I have used \lstMakeShortInline[style=mystyle,language={[PTX]ProTeX}]!to make ! sign as delimiters for inline code snippets. Note: When compiled in overleaf(or TeXlive) it produces an error as undefined control sequence. Note: If the lines from \begin{box2} to \end{box2} (located at the end) is replaced by any random text the error goes away. So, the problem might be in that lines but I still cannot figure out

4
  • please make a small complete example and add it as a code block to the question, do not use external links as the question is archived here forever and willnot be understandable if that oveleaf project changes Commented Feb 16, 2022 at 15:25
  • probably unrelated but why define these with arguments? \newcommand{\n}[1]{\newline}\newcommand{\p}[1]{\par} Commented Feb 16, 2022 at 15:30
  • @David Carlisle thanks for pointing out. I have not noticed that there were arguments as wrote them in hurry although it has no impact on overall compilation process. I will rectify them later. Commented Feb 16, 2022 at 20:25
  • 1
    well if you make a newline with abc \n xyz then the current definition will silently discard the x. (I am surprised you need shortcut macros for \newline or \par since neither should appear in documents except in very unusual circumstances. Commented Feb 16, 2022 at 20:27

0

You must log in to answer this question.

Browse other questions tagged .