[pdftex] [OT] latex questions

Heiko Oberdiek oberdiek at uni-freiburg.de
Wed Feb 5 16:07:26 CET 2003


On Wed, Feb 05, 2003 at 07:55:08PM +0700, The Thanh Han wrote:

> while translating "the not so short introduction into latex2e" to
> vietnamese, I have two latex questions:
> 
> 1) codes between \begin{example} ... \end{example} are not typeset
> properly. If I have some vietnamese characters in the examples, they are
> typeset under the caret notation like ^^be. Using tcx instead of inputenc
> fixed this problem, however I wonder why I cannot use inputenc.

I have looked at the sources of
ftp://ftp.dante.de/tex-archive/info/lshort/english/lshort-4.00.src.tar.gz
and found that the example environment uses the verbatim package.
First it writes the contents to a file and reads this later
by \verbatiminput.
  \start at line can be used as hook to reset the catcode of ^, so that
characters given by the caret notation are recogniced. Of course
the of ^ for the character ^ is now problematic. You can also give it in
caret notation: ^^e5. However, LaTeX will complain a "not in math mode"
error, so this character has to be filtered out and replaced by a
safe form (eg. with catcode 12).

Example file:

\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{verbatim}

\makeatletter
\newwrite\example at out
\newenvironment{foo}{%
  \begingroup
    \immediate\openout \example at out \jobname.exa
    \let\do\@makeother\dospecials\catcode`\^^M\active
    \def\verbatim at processline{%
      \immediate\write\example at out{\the\verbatim at line}%
    }%
    \verbatim at start
}{%
    \immediate\closeout\example at out
  \endgroup
  \begingroup
    \expandafter\def\expandafter\verbatim at startline\expandafter{%
      \verbatim at startline
      \catcode`\^=7 %
    }%
    \let\saved at verbatim@addtoline\verbatim at addtoline
    \def\verbatim at addtoline##1{%
      \toks@={}%
      \caret at verbatim@addtoline##1^\@nil
      \expandafter\saved at verbatim@addtoline\expandafter{\the\toks@}%
    }%
    \verbatiminput{\jobname.exa}%
  \endgroup
}
\def\caret at verbatim@addtoline#1^#2\@nil{%
  \toks@=\expandafter{\the\toks@#1}%
  \ifx\\#2\\%
  \else
    \@ReturnAfterFi{%
      \begingroup
        \edef\x{\endgroup\toks@={\the\toks@\string^}}%
      \x
      \caret at verbatim@addtoline #2\@nil
    }%
  \fi
}
\long\def\@ReturnAfterFi#1\fi{\fi#1}
\makeatother

\begin{document}
\begin{foo}
\Large This is large.
Umlauts: äüöß
Caret notation: ^^be
Math: 2^^5e10=1024
\end{foo}
\end{document}


> 2) how can I have bookmarks displayed closely to the original text, ie if
> a character is avail. in PDFDocEncoding then it is written as is, otherwise
> an accented letter should be replaced by its base letter. For examle, if \~\i
> is not in PDFDocEncoding then it should be written out as i. hyperref seems
> to ignore characters that are not in PDFDocEncoding.

It does ignore:
  \documentclass{article}
  \usepackage{hyperref}
  \begin{document}
  \section{Hello: \~\i}
  \end{document}
generates:
  Package hyperref Warning: Glyph not defined in PD1 encoding,
  (hyperref)                removing `\texttilde+\i' on input line 5.

Solution, add the following after \usepackage{hyperref}:
  \DeclareTextCompositeCommand{\~}{PD1}{\i}{i}

Yours sincerely
  Heiko <oberdiek at uni-freiburg.de>
-- 


More information about the pdftex mailing list