Document ClassesAn incompatible package problem

Information and discussion about specific document classes and how to create your own document classes.
Post Reply
kergoog
Posts: 3
Joined: Wed Oct 31, 2012 3:55 pm

An incompatible package problem

Post by kergoog »

Hi,

I'm writing my thesis which contains several chapters. In one chapter I have psuedo-code while another contains a lot of special equations. The problem is for the psuedo-code I need the algorithmix package and the equations requires a package called zed-csp, but when I include both in my document using "usepackage", I can't compile anymore because one of the pseudo-codes files complains of a "missing $ inserted".

Is there a way to understand and hopefully fix this? If not, is there a way of using both packages in the same document?

Thanks,
Kery.

Recommended reading 2024:

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

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

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

An incompatible package problem

Post by Stefan Kottwitz »

Hi Kery,

welcome to the board!

The packages work together. Here's an example, which is compilable without error:

Code: Select all

\documentclass{article}
\usepackage{algorithmicx}
\usepackage{zed-csp}
\begin{document}
\begin{schema}{Test}
text
\end{schema}
\end{document}
To get your case fixed, you could post a Infominimal working example which shows the problem, i.e. a reduced copy of your code which brings this error when tested.

Stefan
LaTeX.org admin
kergoog
Posts: 3
Joined: Wed Oct 31, 2012 3:55 pm

An incompatible package problem

Post by kergoog »

Hi Stefan,

Thanks for your reply. I assumed it was the algorithmicx package, but perhaps the problem is caused in algorithm or algpseudocode. Here is my header file...

Code: Select all

\documentclass[twoside,11pt]{Latex/Classes/PhDthesisPSnPDF}
%
% PACKAGES IN USE
%
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{epstopdf}
\usepackage{zed-csp}
% for psuedo-code
\usepackage{algorithmicx}
\usepackage{algorithm}
\usepackage{algpseudocode}
And this is causing a problem in the following code...

Code: Select all

\begin{algorithmic}[1]
\Function{Open}{$AtomicObject$}
	\State $scratch \gets \Call{Get}{cache, AtomicObject}$
	\If{$scratch = \textbf{null}$}
		\State $scratch \gets \Call{Copy}{AtomicObject_{VERSION}}$
		\State $\Call{Put}{cache, AtomicObject, scratch}$
	\EndIf
	\State \textbf{return} scratch 
\EndFunction
\end{algorithmic}
The error message I'm getting is...

Code: Select all

! Missing $ inserted.
<inserted text> 
                $
l.6 	\If
        {$scratch = \textbf{null}$}
? 
Hopefully this clarify things?
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

An incompatible package problem

Post by Stefan Kottwitz »

A real MWE would be better than posting code snippets. Each reader would have to built his own test document because you did not take the time but simply copied and pasted parts. Just think about this next time - the easier you make it for the readers, the higher the chance to get a fix.

Well, I could build and test and verify this, it's just a name clash, since both algpseudocode and zed-csp define a macro \If. Here's how you can save and restore the original algorithmicx \If:

Code: Select all

\usepackage{algorithmicx}
\usepackage{algorithm}
\usepackage{algpseudocode}
\let\algIf\If
\usepackage{zed-csp}
\let\If\algIf
It happens sometimes, a package author can choose a name which another one already used. A solution for such clashes could be that package authors would use a common naming convention for example prefixing with the package name.

Stefan
LaTeX.org admin
kergoog
Posts: 3
Joined: Wed Oct 31, 2012 3:55 pm

Re: An incompatible package problem

Post by kergoog »

Okay, I see now.

Thanks Stefan.
Post Reply