5

Context: I've inherited a mess of latex notes from another faculty member; these are processed by using a home-brew system that does lots of clever stuff ... but that means that I must work on them using the linux systems at the office, and also means that finding bugs ends up being a binary-search process, because the clever processing eats up all the error messages and mangles them.

Here's the thing: a typical file looks like this:

@course{coursehead}
@lec{17}{\textit{(Provisional)} Analysis, Combinatorics}
@cs{coursebegin}
@localnotes{obj}

@localnotes{racket/text/stars-and-stripes}
@localnotes{racket/text/analysis}

which turns out to mean (in real LaTeX) just this:

\include{../../latex/coursehead}
\title{Lecture 17 \textit{(Provisional)} Analysis, Combinatorics}
\include{../../latex/coursebegin}
\include{obj}

\include{racket/text/stars-and-stripes}
\include{racket/text/analysis}

So if I could just "define" "@localnotes" to mean "\include", I'd be about 90% of the way to being able to work with the notes without breaking anything from the other system.

Question: Is there a way to make something like "@localnotes" act as a latex macro? Perhaps equally important: is it certain that there is no way to do so? {If it can't be done, I'd like to stop looking for ways to do it!}.

I'm not very tex-savvy. At about the point where I see "makeatletter", I know that I'm about to not understand whatever follows. But if there's a solution that somehow uses this, I'll slog through it until I understand it.

Thanks in advance.

John
  • 447
  • 1
    What the author's done here is defined @ to mean the same thing as \ -- certainly not something I'd ever do myself. It's very possible (and even common to do this sort of thing in package code) but I wouldn't recommend it in an 'author-level' document. I would take the time to turn all those @s into \s. – Sean Allred Oct 21 '15 at 16:32
  • As for the homebrew system, you can easily turn all these things into a key-value interface which will be much easier for that system to parse anyway. – Sean Allred Oct 21 '15 at 16:38
  • I think you're mistaken. What the author has done is write a program that consumes this file and spits out (in some hidden directory) an actual latex file in which the @-things are replaced with various -things, and then runs latex on THOSE. I'm asking how I might do the thing that you thought that the author did. :) – John Oct 21 '15 at 16:38
  • Ah, well then :) If these @ commands aren't going to be processed by TeX, you shouldn't be looking for a TeX way to define them. – Sean Allred Oct 21 '15 at 16:39
  • When I work with these same files, using Tex-shop, or TeXworks, or whatever, on my Windows machine, they actually WILL be processed by LaTeX, and I'm hoping to make it possible to do this by including a few definitions that make these things behave in the way I need, but without breaking the way that they're processed on the Linux system, because that processing does many other useful things (like putting them up on the course website, creating multiple versions of the PDF for homeworks --- one of which includes solutions, and is not distributed to students --- etc.). – John Oct 21 '15 at 16:42
  • That sounds like a fantastically integrated system :) Too bad it was done with this interface. Is @ currently processed by LaTeX, or are you introducing the ability to compile these notes by yourself? (While it's certainly possible in TeX, it might be easier to introduce some flexibility in the external system. I'm going to continue under the assumption that this should be processed by TeX directly.) – Sean Allred Oct 21 '15 at 16:46
  • Sorry I wasn't clear -- definitely everything here is LaTeX, not TeX. I believe that in the current system, the "@" gets swallowed up by a pre-latex process and converted into some sort of macro, or perhaps what happens is that the inclusion is actually performed, so that the temporary latex file now has many more lines in it, but no @-signs. I didn't have the heart to go in and look at machine-generated latex. :( – John Oct 21 '15 at 17:39

2 Answers2

4

Just change @ to be the same as the backslash, after giving the appropriate definitions.

TeX doesn't bother what characters have category code 0, it just follows instructions. ;-) And it's immaterial what category code 0 character has been used for defining the macro.

\documentclass{article}

\newcommand\course[1]{\input{../../latex/#1}}
\newcommand\lec[2]{Lecture #1 #2}
\newcommand\cs[1]{\input{../../latex/#1}}
\newcommand\localnotes[1]{\input{#1}}

\begin{document}

\catcode`@=0

@course{coursehead}
@lec{17}{\textit{(Provisional)} Analysis, Combinatorics}
@cs{coursebegin}
@localnotes{obj}

@localnotes{racket/text/stars-and-stripes}
@localnotes{racket/text/analysis}

\end{document}

In the document environment, after \catcode`@=0, you can use @cs or \cs with exactly the same result.

egreg
  • 1,121,712
3

Here is a very simplified implementation of what you can do:

First: 123; Second: 456

\documentclass{article}

\usepackage{filecontents}
\begin{filecontents*}{inputfile.tex}
@somemacro{123}{456}
\end{filecontents*}

\newcommand{\somemacroprocess}[2]{First: #1; Second: #2}

\begin{document}

\begingroup
\catcode`@=0
\newcommand{@somemacro}{\somemacroprocess}
\input{inputfile}
\endgroup

\end{document}

The idea is to make @ act just like \ by changing its category code via

\catcode`@=0

That way you can define a macro called @somemacro that matches whatever you have in your input file. I've created a macro \somemacroprocess to be the replacement for @somemacro locally (inside a group), while defining \somemacroprocess in the usual way (outside the group).

Werner
  • 603,163
  • This looks like exactly what I want (and similar to @egreg's answer, but perhaps safer, in case my document foolishly contains an email address...) I'll give it a try and report back. (BTW, not only may it do what I want, but I've now learned about "begingroup/endgroup", which I'd never seen before. Yay, Stackexchange!) – John Oct 21 '15 at 17:36