Document ClassesClass vs Document Code Mismatch

Information and discussion about specific document classes and how to create your own document classes.
Post Reply
User avatar
gseba
Posts: 1
Joined: Wed Oct 03, 2007 11:30 am

Class vs Document Code Mismatch

Post by gseba »

Hi there,

I have a class, try to invoke macros/commands via my special macro, but I get no expansion in the class when using \newcommandx, while it is working in the document or without the optional first argument.

I provide a MWE. The console output of latexing the document from 4 \typeouts is:

Code: Select all

--- rollover beethoven ---
--- \mwe@{macro}{beethoven} ---
--- rollover beethoven ---
--- rollover beethoven ---
The second comes from within the class, and I expect should be as the other three!

Class is the file mwe.cls:

Code: Select all

\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesClass{./mwe}
[2011/10/14 v1.0
 A mwe class]
\IfFileExists{xargs.sty}{%
  \RequirePackage{xargs}}{%
  \ClassError{./mwe}{%
    The xargs package was not found.}{%
    The xargs package provides for commands and environments.%
  }}
\newcommand\mwe@test[1]{\typeout{--- #1 ---}}
\newcommand\mwemacro[1]{rollover #1 ---}
\newcommandx\mwe@[2]{\@nameuse{mwe#1}{#2}}
\mwe@test{\mwe@{macro}{beethoven}}
\renewcommandx\mwe@[3][1=mwe]{\csname#1#2\endcsname{#3}}% here
\mwe@test{\mwe@{macro}{beethoven}}
\LoadClass[a4paper,10pt,twoside,openright]{report}[2007/10/19]
\endinput
It loads report; in the same directory, the document is the file mwe.tex:

Code: Select all

\documentclass{./mwe}
\begin{document}

\makeatletter
\newcommandx\myt@st[1]{\typeout{--- rollover #1 ---}}
\newcommandx\use@[3][1=my]{\@nameuse{#1#2}{#3}}
\use@{t@st}{beethoven}
\makeatother

\TeX\space it.

\newcommand\mytest[1]{\typeout{--- rollover #1 ---}}
\newcommand\use[3][my]{\csname#1#2\endcsname{#3}}
\use{test}{beethoven}
\end{document}

The class uses package xargs. Actually, I need my special invocation command for \newcommandx's defined with optional trailing arguments too (square brackets). There are in fact a series of similar special macros to replace many otherwise occurring \@nameuse's.

Yet I cannot seem to fix this. Why is there no expansion in the class code for the \newcommandx with optional first parameter?

Thanks for your help or reply,
Sebastian

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

Post Reply