[texhax] strange problem with a sty file and \catcode

Vafa Khalighi vafakhlgh at gmail.com
Fri Nov 19 09:26:09 CET 2010


If i create a simple sty file, say mypackage.sty which includes:

%%%%%%%%%%%%%%%%%%%%%%%%%%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{mypackage}
\catcode`$=11
\newcommand*{\eqcommand}[2]{%
\expandafter\@ifdefinable  \csname#1\endcsname{%
\expandafter\let\csname#1\expandafter\endcsname\csname#2\endcsname}}
\eqcommand{new$command}{newcommand}
\endinput
%%%%%%%%%%%%%%%%%%%%%%%%%%

then this tex file gives error:

 \documentclass{article}

\usepackage{mypackage}

\new$command\test{Test}

\begin{document}

This is a test\TeX

\end{document}


and the error is:


! Undefined control sequence.

<recently read> \new

 l.3 \new

$command\test{Test}

?


Then I I change my tex file so that I leave a blank line after
\usepackage{mypackage}, no error happens:


\documentclass{article}

\usepackage{mypackage}


\new$command\test{Test}

\begin{document}

This is a test\TeX

\end{document}


but even without using a package, this gives no error:




\documentclass{article}

\makeatletter

\catcode`$=11

\newcommand*{\eqcommand}[2]{%

\expandafter\@ifdefinable \csname#1\endcsname{%

\expandafter\let\csname#1\expandafter\endcsname\csname#2\endcsname}}

\eqcommand{new$command}{newcommand}

\makeatother

\new$command\test{Test}

\begin{document}

This is a test\TeX

\end{document}



So can you please enlighten me why this error only happens when my
definitions are inside sty file and how can I fix this?

-- 
I prefer the most bloodcurdling death to living with humility. The only
country I am faithful to, is IRAN. Do not denigrate my last moments...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://tug.org/pipermail/texhax/attachments/20101119/7e3ea739/attachment.html>


More information about the texhax mailing list