LaTeX forum ⇒ MiKTeX and proTeXtError: "Loading a class or package in a group. \usepackage" with .cls file

Information and discussion about MikTeX distribution for Windows and the related proTeXt: Installing, updating, configuring
caheo1294
Posts: 10
Joined: Wed Aug 18, 2021 2:10 am

Error: "Loading a class or package in a group. \usepackage" with .cls file

Postby caheo1294 » Mon Jul 22, 2024 12:08 pm

Hello everybody,

I am writing my thesis with .cls file. This morning, everything worked well, and suddenly, my dumb brain decided to mess around with the MikTeX Console. And of course, I could not compile from the .cls file anymore.

So I decided to reinstall the MikTeX Console. And again, I could not compile the .cls. It gives me this error: "Loading a class or package in a group. \usepackage", like a bunch of them. Some of other errors are "Loading a class or package in a group. \RequirePackage." At first I thought because I used
\usepackage{A,B,C}
, so I tried to separate them like
\usepackage{A}
\usepackage{B}
and so on; but it still did not work. Then I tried to replace all
\usepackage
with
\RequirePackage
in the .cls file but it still did not work.

However, when I try to compile from a single .tex file. It works well. It does not give me any errors at all. I only encountered this problem when I compiled it with a .cls file.

I don't know what I am supposed to do now, and I wanna cry. Could anyone please help me with this? Please be gentle with this dumb brain :< Thanks xoxoxo

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics
rais
Posts: 419
Joined: Sun Nov 16, 2014 8:51 pm

Error: "Loading a class or package in a group. \usepackage" with .cls file

Postby rais » Mon Jul 22, 2024 3:22 pm

Well, a class file lacks a document body---at least, there shouldn't be any in a class file to begin with--so a class file is not supposed to be compiled directly. Nor a style file, for that matter. Rather, create a .tex file that loads the class (or style) you're working on and compile that .tex file.

BTW: within class and style files, \RequirePackage is preferred over \usepackage (and within a .tex document, it's the other way around). IIRC, I read something about this in clsguide

KR
Rainer

caheo1294
Posts: 10
Joined: Wed Aug 18, 2021 2:10 am

Error: "Loading a class or package in a group. \usepackage" with .cls file

Postby caheo1294 » Mon Jul 22, 2024 3:42 pm

rais wrote:Well, a class file lacks a document body---at least, there shouldn't be any in a class file to begin with--so a class file is not supposed to be compiled directly. Nor a style file, for that matter. Rather, create a .tex file that loads the class (or style) you're working on and compile that .tex file.

BTW: within class and style files, \RequirePackage is preferred over \usepackage (and within a .tex document, it's the other way around). IIRC, I read something about this in clsguide

KR
Rainer


Thank you for your reply. Yeh I am aware that I cannot compile from the class file haha.

What I meant is I use
\usepackage
in a .cls file (let's say it is "Main.cls") and in my .tex file (e.g., "Paper.tex"), I begin it with
\documentclass[a4paper, 12pt, oneside]{Main}
. When I compile from Paper.tex file, it says "Loading a class or package in a group. \usepackage". My apologies for the confusion.

I have tried to replace \usepackage with \RequirePackage; but it did not work. It used to work with \usepackage but because I messed it up, it is now not working. :<


Return to “MiKTeX and proTeXt”

Who is online

Users browsing this forum: No registered users and 4 guests