14

I have searched for "namespaces", but all of these posts seem to ask for something way more advanced.

The problem I encounter can be solved by renaming everything, but that does not seem "right". There are bunch of commands in my document such as \renewcommand{\vec}[1]{\mathbf{#1}} for vectors in the physics part. However, I would like to include papers in my final thesis where sometimes the same command is used with a different definition (different field). Hence, the files would compile on themselves, but if I include them in my larger document (such that they get page numbers and included in the TOC) this will give collisions.

So my question is: Is it possible to "rewrite" a prefix in a command on a per-file basis? That would be, I define \newcommand{\jonas@vec}[1]{\mathbf{#1}} and in my particular document jonas.tex I would rewrite all commands \jonas@vec to the one with the part without \jonas@. This would allow me to use the same syntax, but have a different definition.

4
  • 7
    Redefinitions can be scoped within a \begingroup...\endgroup, so it is just a matter of figuring out a system to define where the group begins and ends. I usually limit the redefinitions to be within environments so only that environment sees this new definition, but outside of this specific environment the usual meaning is applied. Oct 17, 2012 at 16:21
  • @PeterGrill Thanks! So perhaps the filehook (I believe) package will help me there?
    – JT_NL
    Oct 17, 2012 at 16:47
  • 3
    Could you make some more examples of redefined commands?
    – egreg
    Oct 17, 2012 at 17:29
  • 2
    I will come back to this question asap, have to write the paper now, not mess with getting the .tex better :-).
    – JT_NL
    Oct 21, 2012 at 15:12

1 Answer 1

4

Ok, here's an attempt at an answer. If it's not helpful in your particular case, maybe we can rework it together.

The key to making redefinitions local to a particular document is grouping the respective code, as already remarked in the comments.

The main question is how you're including the individual documents. Assuming you're using the combine class, the main document might look something like this:

\documentclass[report]{combine}

\usepackage[paperwidth=3in,paperheight=4.5in]{geometry}

\usepackage{combinet}

\begin{document}

\title{My title Main}

\author{Myself}

\maketitle

\tableofcontents

\begin{papers}

  \import{testinclude1}

  \import{testinclude2}

\end{papers}

\chapter{Main Chapter}

$\vec{A}$

\end{document}

Assume further that testinclude1.tex looks like

\documentclass{article}

\renewcommand{\vec}[1]{\mathbf{#1}}

\begin{document}

\title{My title One}

\author{Myself}

\maketitle

foo bar

$\vec{A}$

\end{document}

Then the redefinition of \vec will "spill" into testinclude2.tex, but not out of the papers environment (as it is local to environments).

If you enclose the \import calls in {} (which also form a group), then the redefinition of \vec will be completely local to testinclude1.tex:

{\import{testinclude1}}

{\import{testinclude2}}

Not knowing the combine class in detail, I don't expect any averse effects from the grouping as things like table of contents entries work through the .aux file.

example output

Does this help you in any way?

1
  • This is just perfect! :-). I was unaware of the existence of the 'combine' class.
    – JT_NL
    Dec 1, 2012 at 14:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .