# Can a class file be merged into a .tex file?

I am trying to use the `res` class in a context where it may not be possible to direct LaTeX to the the `res.cls` file location in the usual way. (For more non-essential details, see my question on StackOverflow.)

The `res` class appears to be based on the `article` class:

``````\PassOptionsToClass{11pt,12pt}{article}
``````

So my question is, are there any obstacles to me simply using the `article` class in my `.tex` file, and copying the content of `res.cls` to the `.tex` file, so that only one file is required for pdflatex to generate a pdf?

I'm imagining something similar (in principle) to putting the CSS for a HTML page inside `<style> ... </style>` tags in the `<head>` rather than in a separate document. Of course, it wouldn't be a direct copy & paste (I've tried that); I presume there would be some modifications necessary. But is it theoretically possible?

Thanks in advance for you help.

• all except the options can just be copied to the preamble, the option handling you would have to adjust, but that class doesn't have much, but why can't you arrange your service to cd to the document directory and then run pdflatex on the file as normal? – David Carlisle Mar 15 '17 at 23:14
• I guess the first thing that causes trouble is the `\ProvidesClass` declaration, you should omit it too. – GuM Mar 15 '17 at 23:20
• The option handling is easy too adjust, just set the relevant switches manually. Of course, you already know that you need to bracket the class code between `\makeatletter` and `\makeatother`, don’t you? :-) Please consider answering your own question, if you succeed, giving a concise description of what you did. You can accept your own answer, too (as you perhaps already know). – GuM Mar 15 '17 at 23:33
• You can change e.g. `TEXMFHOME` at runtime e.g. `TEXMFHOME=/d pdflatex <filename>.tex` if you had `/d/tex/latex/res/res.cls`, for example. – cfr Mar 16 '17 at 2:40
• You can add the code of the class within a `filecontents` environment before `\documentclass` to write the class file into the working directory. TeX should find it there. – Schweinebacke Mar 21 '17 at 8:22

Yes, it is possible. My final combined `.tex` file looked like:

``````\documentclass[line,margin]{article}

\makeatletter

\typeout{Document Style `res' <26 Sep 89>.}
\NeedsTeXFormat{LaTeX2e}[1995/12/01]

\newif\if@line
\newif\if@margin

\DeclareOption{line}{\@linetrue}
\DeclareOption{centered}{\@linefalse}

\DeclareOption{margin}{\@margintrue}
\DeclareOption{overlapped}{\@marginfalse}

\ExecuteOptions{overlapped,centered}
\ProcessOptions\relax

\nofiles

\newtoks\tabular@text       % holds the current list being processed