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 have this short code that uses the \aftergroup command to inject a \centering before inserting a figure and then tries and restore the paragraph settings after the image is typeset.

enter image description here

I am trying to modify the code so that it can detect the environment that was in before the macro was expanded, i.e if the previous settings were justified then after the image is typeset the environment is restored. How do I do this?

Minimal shown below:

\documentclass{article}
\usepackage{graphicx,lipsum}

\def\agraphic{{\begin{minipage}{3cm}\par \includegraphics[width=\textwidth]{./graphics/amato}\end{minipage}\par}}
\def\testafter{{ \gdef\aword{\centering}\aftergroup\aword\aftergroup \agraphic\aftergroup\flushleft }}
\begin{document}
\lipsum[1]
\testafter
\lipsum[2]
\agraphic
\lipsum[1]
\end{document}
share|improve this question
    
What about @currenvir? –  mbork Nov 14 '11 at 23:22
2  
Also, you might want to test the values of \leftskip and \rightskip. –  mbork Nov 14 '11 at 23:23
    
Isn't it sufficient to say \par{\centering\includegraphics[...]{...}\par}? –  egreg Nov 14 '11 at 23:24
    
You right I am not sure if @currenvir would do, values could be set from the class definitions or from inline code. –  Yiannis Lazarides Nov 14 '11 at 23:26
    
@egreg This is an extract from some long code, I need to escape outside the enclosing groups. –  Yiannis Lazarides Nov 14 '11 at 23:27

1 Answer 1

up vote 6 down vote accepted

It's possible to avoid cumbersome code by simply saying

\par{\centering\includegraphics[...]{...}\par}

that will restore the previous settings, but center the picture.

share|improve this answer

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.