preview-latex: Misplaced previews

 
 6.4 Misplaced previews
 ======================
 
 If you are reading this section, the first thing is to check that your
 problem is not caused by x-symbol in connection with an installation not
 supporting 8-bit characters (Seex-symbol interoperation).  If not,
 here's the beef:
 
    As explained previously, Emacs uses pseudo-error messages generated
 by the 'preview' package in order to pinpoint the exact source location
 where a preview originated.  This works in running text, but fails when
 preview material happens to lie in macro arguments, like the contents of
 '\emph'.  Those macros first read in their entire argument, munge it
 through, perhaps transform it somehow, process it and perhaps then
 typeset something.  When they finally typeset something, where is the
 location where the stuff originated?  TeX, having read in the entire
 argument before, does not know and actually there would be no sane way
 of defining it.
 
    For previews contained inside such a macro argument, the default
 behaviour of preview-latex is to use a position immediately after the
 closing brace of the argument.  All the previews get placed there, all
 at a zero-width position, which means that Emacs displays it in an order
 that preview-latex cannot influence (currently in Emacs it is even
 possible that the order changes between runs).  And since the placement
 of those previews is goofed up, you will not be able to regenerate them
 by clicking on them.  The default behaviour is thus somewhat
 undesirable.
 
    The solution (like with other preview problems) is to tell the LaTeX
 'preview' package how to tackle this problem (SeeThe LaTeX style
 file).  Simply, you don't need '\emph' do anything at all during
 previews!  You only want the text math previewed, so the solution is to
 use '\PreviewMacro*\emph' in the preamble of your document which will
 make LaTeX ignore '\emph' completely as long as it is not part of a
 larger preview (in which case it gets typeset as usual).  Its argument
 thus becomes ordinary text and gets treated like ordinary text.
 
    Note that it would be a bad idea to declare
 '\PreviewMacro*[{{}}]\emph' since then both '\emph' as well as its
 argument would be ignored instead of previewed.  For user-level macros,
 this is almost never wanted, but there may be internal macros where you
 might want to ignore internal arguments.
 
    The same mechanism can be used for a number of other text-formatting
 commands like '\textrm', '\textit' and the like.  While they all use the
 same internal macro '\text@command', it will not do to redefine just
 that, since they call it only after having read their argument in, and
 then it already is too late.  So you need to disable every of those
 commands by hand in your document preamble.
 
    Actually, we wrote all of the above just to scare you.  At least all
 of the above mentioned macros and a few more are already catered for by
 a configuration file 'prauctex.cfg' that gets loaded by default unless
 the 'preview' package gets loaded with the 'noconfig' option.  You can
 make your own copy of this file in a local directory and edit it in case
 of need.  You can also add loading of a file of your liking to
 'preview-default-preamble', or alternatively do the manual disabling of
 your favorite macro in 'preview-default-preamble', which is customizable
 in the Preview Latex group.