GeneralProblem with mcode.sty

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
nanocyte
Posts: 2
Joined: Thu Jan 23, 2014 7:39 pm

Problem with mcode.sty

Post by nanocyte »

Hi there,
I'm using texmaker (on OS X Mavericks). This is my first report I'm writing with LaTeX so I'm not that quite familiar with LaTeX.

I get a strange behaviour but do not have any clue how to move on...

This is a minimal example:

Code: Select all

\documentclass[12pt,english,a4paper,oneside]{scrreprt}
\usepackage{babel}

\makeatletter
\renewcommand{\@makechapterhead}[1]{
\vspace*{4 pt}
{{\setlength{\parindent}{0 pt}
\raggedright \LARGE \chaptername~\thechapter

}
{\setlength{\parindent}{0 pt}
\raggedright \huge \bfseries #1

}}
\vspace{30 mm}
}
\makeatother 

\usepackage[numbered]{mcode} 

\begin{document}

\chapter{Test}
Here is a reference to appendix: \ref{appendix:data}. Hello World!

\begin{appendix}

\chapter{Data}
\label{appendix:data}
Test

\end{appendix}

\end{document}
Though... I want a custom chapter heading style. As you can see, I'm using mcode.sty which I downloaded from this source: http://www.mathworks.com/matlabcentral/ ... ex-package and put it into the same directory as my example file.

If I delete the line \usepackage{mcode} everything is good except for my custom header style. But with this line, there are two things bothering me:
- see attached screenshot: there's a little "chapter" before my "Chapter 1"
- the reference to the appendix is not printed, there should a "(...) appendix: A. Hello world!"

I tried to extract code from mcode.sty into my example (what I think LaTeX is processing within). But than everything is good, no little "chapter", no missing reference.

Can anyone assist? That would be awesome!
Attachments
Bildschirmfoto 2014-01-23 um 18.50.38.JPG
Bildschirmfoto 2014-01-23 um 18.50.38.JPG (37.77 KiB) Viewed 9500 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Problem with mcode.sty

Post by cgnieder »

Hi and welcome to the LaTeX community!

I don't know the mcode package but it seems unrelated to the chapter headings...

In any way KOMA-Script's headings are best modified using KOMA-Script's interfaces:

Code: Select all

\documentclass[12pt,english,a4paper,oneside,chapterprefix=true]{scrreprt}
\usepackage{babel}

\setkomafont{chapterprefix}{\normalfont\LARGE}
\setkomafont{chapter}{\normalfont\raggedright\huge\bfseries}
\renewcommand*\chapterheadendvskip{\vspace{30mm}}
\renewcommand*\chapterformat{%
  \mbox{\chapappifchapterprefix{\nobreakspace}\thechapter\enskip}%
}

\begin{document}

\chapter{Test}
Here is a reference to appendix: \ref{appendix:data}. Hello World!

\appendix

\chapter{Data}\label{appendix:data}

Test

\end{document}
KOMA-heading.png
KOMA-heading.png (12.81 KiB) Viewed 9485 times
Regards
site moderator & package author
nanocyte
Posts: 2
Joined: Thu Jan 23, 2014 7:39 pm

Problem with mcode.sty

Post by nanocyte »

Thanks for the reply.

It seems like my problem is somehow related to OS X (or my installation of TeX, I'm using TeX Live Utility). I tried my example from above in Linux and Windows and no problem.

Point is, I want to add some XML and Matlab code to the appendix. So I wrote my own listing style for XML by merging what mcode.sty contains with this source: http://stackoverflow.com/questions/7419 ... onal-books .
Works for me (though I still don't like workaround). Maybe I have to try and reinstall TeX...

Heres my alpha version of XML listing style:

Code: Select all

%% SYNTAX OUTPUT ------------------------------------------------------------
\usepackage{listings}

% the following is needed for syntax highlighting
\usepackage{color}

\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}

%\usepackage[scaled]{DejaVuSansMono}
\usepackage[scaled=0.85]{beramono}

% XML listing
\lstset{ %
  language=Xml,					% the language of the code
  basicstyle=\ttfamily\selectfont\small,  
  								% the size of the fonts that are used for the code
  stepnumber=1,					% the step between two line-numbers. If it's 1,
  								% each line will be numbered
  numbersep=3mm, 				% how far the line-numbers are from the code
  numbers=left,					%
  numberstyle=\tiny,   			%
  extendedchars=true,	
								%
  columns=fixed,					%
  aboveskip={1.5\baselineskip},	%
  mathescape=false,escapechar=§,	% 
								%
  backgroundcolor=\color{white},	% choose the background color
  showspaces=false,				% show spaces adding particular underscores
  showstringspaces=false,		% underline spaces within strings
  showtabs=false,				% show tabs within strings adding underscores
  frame=single,					% adds a frame around the code
  framexleftmargin=0mm,			%
  xleftmargin=6mm,				%
  								%
  rulecolor=\color{black},		% if not set, the frame-color may be changed on
  								% line-breaks within not-black text 
  tabsize=4,						% sets default tabsize
  breaklines=true,         		% sets automatic line breaking
  breakatwhitespace=false,    	% if automatic breaks only at whitespace
  keywordstyle=\color{blue},  	% keyword style
  commentstyle=\color{dkgreen},	% comment style
  stringstyle=\color{mauve}, 	% string literal style
  escapeinside={\%*}{*)},   		% if you want to add a comment within your code
  morekeywords={*,...}      		% if you want to add more keywords to the set
}
Post Reply