Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'll ask the question first and then explain why it is so. I have the following .tex file:

\documentclass{article}    
\newsavebox{\myquote}
\setbox\myquote=\hbox{\begin{normalsize}\verb.'.\end{normalsize}}

\usepackage{upquote} % convert verbatim ' from left single quote to a "normal" single quote

\begin{document}
Test: \verb.'. vs \usebox{\myquote}
\end{document}

In this tex file, the \verb.'. turns out as a ', and the \usebox{\myquote} looks like a curly left single quote. This is because even though I \usepackage{upquote} (which converts the curly left single quote to the straight single quote within verbatim/verb), it's loaded in after the definition of \myquote so it's too late for the upquote package to affect what sort of quote happens in \myquote.

Question: assuming I can only put code after the \setbox line, is there some way to make the quote mark in \myquote appear as a straight single quote?

I am basically looking to add a command like \edef\myquote\myquote after the \usepackage{upquote}, so that the definition of \myquote is basically re-evaluated before assigning it back to \myquote. The re-evaluation will cause the \verb.'. to be parsed according to the modifications made in \usepackage{upquote}, causing the quote to be a single quote again.

You may ask why I don't use load upquote before I define myquote; well, I am using a document generation package called Sweave (for the language R). I basically can embed write R code into my (otherwise LaTeX-looking) document, call Sweave on it, and it will produce a .tex file with the code (& results) nicely printed within. Sweave inserts all of these \newsavebox commands before the preamble that I put in the original document. That is, I cannot change the order of the \newsavebox command to be after the \usepackage{upquote}.

As a last resort I can copy/paste the \setbox\myquote=\hbox... that gets generated by Sweave into my own document preamble (i.e. after the \usepackage{upquote}), but then should the Sweave package change their definition of \myquote (say they change the normalsize to something else) I'll have to change my definition to remain in sync.

It'd be preferable to do the re-definition as if I only knew the command was \myquote (and knowing it has \verb.'. in it somewhere so that I know the upquote package will have effect) and not its actual definition.

I hope that makes sense.

share|improve this question
1  
No, I don't think that's possible. AFAIK box content is typeset when the box is assigned. The actual code like \begin{normalsize}\verb.'.\end{normalsize} (which BTW should be \normalsize\verb.'.) is not present and available any longer. The box register already contains the lower level typesetting material, which AFAIK can't be really changed any longer. –  Martin Scharrer Mar 29 '12 at 6:41
    
Ok, so I'll just stick to looking at the generated \setbox line & copying it to my preamble after I load in \upquote for now (I know the definitions are not as elegant as they could be, but I have no control over them - they are generated). cheers! –  mathematical.coffee Mar 29 '12 at 6:54
    
@MartinScharrer That's correct: please post it as an answer. –  Joseph Wright Mar 29 '12 at 7:03
    
@JosephWright: Done –  Martin Scharrer Mar 29 '12 at 7:05
    
In addition to Martin's answer it is best to avoid any typesetting in to boxes before begin[document} laTeX makes a paragraph break be an error in that context to discourages but allows single line setbox/savebox settings for legacy compatibility. However many aspects of the font setup are not initialised until begin[document} even if you don't load any packages. (in case you do load packages) –  David Carlisle Mar 29 '12 at 8:17

1 Answer 1

up vote 7 down vote accepted

No, I don't think that's possible. AFAIK box content is typeset when the box is assigned. The actual code like \begin{normalsize}\verb.'.\end{normalsize} (which BTW should be \normalsize\verb.'.) is not present and available any longer. The box register already contains the lower level typesetting material, which AFAIK can't be really changed any longer.

The best solution is to get the definition of the box again and reassign it after loading the formatting packages.

share|improve this answer
    
Thanks, I'll stick to looking for the definition of the box and re-assigning, and just have to take my chances with the definition changing in future versions. –  mathematical.coffee Mar 29 '12 at 8:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.