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.

[edited] finished OK MWE

This is mwe.dtx.

% \iffalse    (METACOMMENT)
%%
%% ---------------------------------------------------------------------
%%
%% Document class `mwe' to use with LaTeX 2e.
%%
%% ---------------------------------------------------------------------
%%
% \fi
%
% \CheckSum{419}
%% \CharacterTable
%%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}
%%
% ^^A \MakeShortVerb{\|}
% \section{Internals}
%
%    \begin{macrocode}
%<class>\NeedsTeXFormat{LaTeX2e}[1995/12/01]
%    \end{macrocode}
%
% \iffalse (Don't show this in the doc).
%<*driver>
         \ProvidesFile{mwe.drv}
%</driver>
% \fi
%    \begin{macrocode}
%<class>\ProvidesClass{./mwe}
        [2012/05/24 v1.0
%<class>        A mwe class]
%    \end{macrocode}
% \iffalse (Omitted from the doc)
%<*driver>
]
%</driver>
% \fi
%
% \subsection{Driver for this document}
%
% This program will extract the following driver from this file:
%    \begin{macrocode}
%<*driver>
\documentclass{ltxdoc}
\EnableCrossrefs
%\DisableCrossrefs % Say \DisableCrossrefs if index is ready
\RecordChanges
%\OnlyDescription % Comment out for implementation details
\CodelineIndex
\begin{document}
  \DocInput{mwe.dtx}
\end{document}
%</driver>
%    \end{macrocode}
% \begin{macro}{\my@op@n}
% \begin{macro}{\my@s@ut}
% \begin{macro}{\protected@write@immediate}
% \begin{macro}{\immediateaddtocontents}
% \begin{macro}{\addtocontentsline}
% \begin{macro}{\my@readwrite@line}
% \begin{macro}{\my@docum@nt}
% \begin{macro}{\my@end@docum@nt}
% \begin{environment}{document}
% \begin{macro}{\my@sym@def}
% \begin{macro}{\my@sym@LANG@def}
% \begin{macro}{\my@s@l@ctl@ngu@g@}
% \begin{macro}{\selectlanguage}
% \begin{macro}{\my@ch@pt@r@}
% \begin{macro}{\@chapter}
% \begin{environment}{symbols}
%    \begin{macrocode}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\RequirePackage[T1]{fontenc}%%%%
\RequirePackage[utf8]{inputenc}%
\RequirePackage{xargs}%%%%%%%%%%
\RequirePackage{acronym,suffix,xargs,xifthen,xspace}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\LoadClass[a4paper,10pt,twoside,openright]{report}[2007/10/19]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newcommandx\my@op@n[3][addprefix=\global,1=template,2=.txt,3=.tex]{%
  \newread\my@file%
  \immediate\openin\my@file=#1\myLANG#2%
  \newwrite\my@fil@%
  \immediate\openout\my@fil@=#1\myLANG#3%
}

\newcommandx\my@s@ut[0][addprefix=\global]{%
  \immediate\closein\my@file%
  \immediate\closeout\my@fil@%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Code borrowed from `multitoc.dtx' of CTAN /macros/latex/contrib/ms
%% Copyright (c) [1998..1999]  Martin Schr\"oder. All rights reserved.

\newcommand*{\protected@write@immediate}[3]{%
      \begingroup
       \let\thepage\relax
       #2%
       \let\protect\string
       \edef\reserved@a{\immediate\write#1{#3}}%
       \reserved@a
      \endgroup
      \if@nobreak\ifvmode\nobreak\fi\fi
   }

\newcommand*{\immediateaddtocontents}[2]{%
  \protected@write@immediate\@auxout
      {\let\label\@gobble \let\index\@gobble \let\glossary\@gobble}%
      {\string\@writefile{#1}{#2}}}

%%
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\addcontentsline#1#2#3{%
  \immediateaddtocontents{#1}{\protect\contentsline{#2}{#3}{\thepage}}}

\newcommandx\my@readwrite@line[2][addprefix=\global\protect,1=-1,2=to]{%
  \catcode`\\=12\catcode`\{=12\catcode`\}=12\catcode`\$=12%
  \catcode`\#=12\catcode`\^=12\catcode`\_=12\catcode`\%=12%
  \let\my@var\endlinechar%
  \endlinechar=#1%
  \immediate\read\my@file#2\my@lin@%
  \endlinechar=\my@var%
  \catcode`\%=14\catcode`\_=8\catcode`\^=7\catcode`\#=6%
  \catcode`\$=3\catcode`\}=2\catcode`\{=1\catcode`\\=0%
  \protected@xdef\my@line{\my@lin@}%
  \ifthenelse{\equal{\my@line}{}}{}{%
  \protected@write@immediate\my@fil@{\relax}{\my@line\@backslashchar\@backslashchar}}%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\let\my@docum@nt\document
\let\my@end@docum@nt\enddocument
\renewenvironmentx{document}[2][1=pre,2]{%
  \my@op@n%
  \my@docum@nt%%%%%
  \input{#1.tex}%
  \ifx\\#2\\\else\selectlanguage{#2}\fi%
  \ignorespaces%%%%%%%%%
}{\my@end@docum@nt%
  \ignorespacesafterend%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newcommandx\my@sym@def[1][addprefix=\global]{%
  \expandafter%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  \newcommandx\csname#1\endcsname[4][addprefix=\global,3,4]{%
    \ifthenelse{\isempty{##3}%
    }{\ifthenelse{\isempty{##4}%
      }{\acro{##1}{{##2}}%%%%%%%%%
      }{\acro{##1}[{##2}]{{##4}}}%
    }{\ifthenelse{\isempty{##4}%
      }{\acro{##1}{{##2}\acroextra{{##3}}}%%%%%%%%
      }{\acro{##1}[{##2}]{{##4}\acroextra{{##3}}}%
    }}%
    \expandafter\gdef\csname##1\endcsname{\acl{##1}\xspace{}}%%
    \expandafter\gdef\csname##1*\endcsname{\acs{##1}\xspace{}}%
  }%
}

\newcommandx\my@sym@LANG@def[2][addprefix=\global]{%
  \expandafter%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  \newcommandx\csname#1#2\endcsname[4][3,4]{%
    \ifthenelse{\isempty{##3}%%%%%%%%%%%%%%%%%%%%%%%
    }{\@nameuse{#1}{##1}{\@nameuse{#2}{##2}}[][##4]%
    }{\@nameuse{#1}{##1}{\@nameuse{#2}{##2}}%%%%%%%%
                        [\@nameuse{#2}{##3}][##4]%%%
    }%
  }%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\let\my@s@l@ctl@ngu@g@\selectlanguage
\renewcommand\selectlanguage[1]{%%%%%%%%%%%
\my@s@l@ctl@ngu@g@{#1}\@nameuse{do\myLANG}}

\let\my@ch@pt@r@\@chapter
\renewcommandx\@chapter[3][1,2,3]{%
  \ifthenelse{\isempty{#1}}{%
    \GenericError{}{empty chapter name}{%%%
      stop}{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      here.}}%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  \ifx\\#3\\\else\selectlanguage{#3}\fi%
  \my@ch@pt@r@[#1]{#1}%
  \addcontentsline{lof}{chapter}{\thechapter\nobreakspace#1}%
  \addcontentsline{lot}{chapter}{\thechapter\nobreakspace#1}%
  \ifx\\#2\\\else\label{chp:#2}\fi%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newenvironmentx{symbols}[1][1]{%
  \pagestyle{empty}%%%%%%%
  \thispagestyle{empty}%%%
  \chapter*{Symbols}%
  \addcontentsline{toc}{section}{Symbols}%
  \begin{acronym}[{#1}]%
}{\end{acronym}%%%%%%%%%
  \clearpage%
}

%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{environment}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{environment}

This is mwe.ins.

\def\batchfile{mwe.ins}
\input docstrip.tex
\keepsilent
\generateFile{mwe.cls}{t}{\from{mwe.dtx}{class}}

This is ltxdoc.cfg.

\PassOptionsToClass{a4paper}{article}
\AtEndOfPackage{%
\hyphenation{tocprelim semifinal draft}
\RequirePackage{indentfirst}%
\RequirePackage{hyperref}%
}

This is mwe.tex.

% -*- mode: latex; unibyte: nil; coding: utf-8 -*-

\documentclass{./mwe}

\usepackage[romanian]{babel}
\usepackage{newunicodechar}

\newunicodechar{ș}{\c{s}}\newunicodechar{Ș}{\c{S}}
\newunicodechar{ț}{\c{t}}\newunicodechar{Ț}{\c{T}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newcommand\RO[1]{\foreignlanguage{romanian}{#1}\xspace{}}
\newcommand\doRO{\relax}
\xdef\myLANG{RO}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\makeatletter

\my@sym@def{sym}
\@expandtwoargs\my@sym@LANG@def{sym}{\myLANG}

\makeatother

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\title{Minimal Working Example}
\author{acronym}

\begin{document}[preamble][romanian]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%--------------------------------------------------------------------%

\inputencoding{latin10}

\makeatletter

\newcounter{my@cnt}%
\setcounter{my@cnt}{0}%

\@whilenum\arabic{my@cnt}<24\do{%
  \my@readwrite@line%
  \stepcounter{my@cnt}%
}

\my@s@ut%

\makeatother

\noindent%
\input{templateRO}

\inputencoding{utf8}

%--------------------------------------------------------------------%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\chapter[Oscilații][osc][romanian]

\HZO~e formula pentru \HZO*.

\end{document}

This is preamble.tex.

% -*- mode: latex; unibyte: t; coding: utf-8 -*-

\maketitle

\begin{symbols}[WORD]

  \symRO{HZO}{Apă}[\hfill făcută din 3 elemente și 2 molecule][$H_2O$]

\end{symbols}

\tableofcontents

The sequence is: latex mwe.ins; pdftex -shell-escape mwe.tex #twice

The file templateRO.txt as specified here -- http://en.wikipedia.org/wiki/Romanian_alphabet#Unicode_and_HTML -- contains 8-bit letters with commas, not cedillas.

Thesis
Submitted in Partial Fulfillment of the Requirements for
the Degree of Doctor of Philosophy
in Computer Science
to the Faculty of Engineering of the
University of Rome
by

Conducător științific
Referenți științifici

Ziua susținerii tezei

Acest document este în domeniul public.

Acknowledgements

Dedicație

Keywords

Lista de acronime
Lista de teoreme
Lista de demonstrații

thank s.

share|improve this question
    
Don't mix encoding. It's better to convert the Latin-10 document into UTF-8. –  egreg May 16 '12 at 16:56
    
@egreg: I have used \inputencoding without problems to include listings in ansi in an utf8-document. I do find this \catcode changes much more doubtful. What's their purpose? –  Ulrike Fischer May 16 '12 at 17:14
    
@UlrikeFischer Here the problem seems to be in what TeX writes out under the latin10 regime. I don't even ask myself what those \catcode instruction are for. –  egreg May 16 '12 at 17:15
    
@egreg \acro writes to the aux. But normally this shouldn't be a problem as it will expand non-ascii chars to LICR-commands (\"a etc.). But if the \catcodes are changed you get non-ascii-chars in the aux-file and together with the encoding changes things get messy. –  Ulrike Fischer May 16 '12 at 18:13
    
You should not have to change the catcodes. inputenc should allow switching between catcodes without that. In fact by making characters catcode 12 you break inputenc's mechanisms entirely. –  David Carlisle May 16 '12 at 18:44

1 Answer 1

The main file should not have the catcode changes they disable inputenc

\documentclass[a4paper,10pt]{report}

\usepackage[T1]{fontenc}
\usepackage[latin10,utf8]{inputenc}
\usepackage[romanian]{babel}
\usepackage{newunicodechar}
\usepackage{acronym}

\newunicodechar{ș}{\c{s}}\newunicodechar{Ș}{\c{S}}
\newunicodechar{ț}{\c{t}}\newunicodechar{Ț}{\c{T}}

\begin{document}

\selectlanguage{romanian}

\inputencoding{latin10}


\input{symbols}



\inputencoding{utf8}

\chapter{Oscilații}

\end{document}

You will need to delete the .aux file so latex will then write a correct one that should look like this:

\relax 
\reset@newl@bel
\select@language{romanian}
\@writefile{toc}{\select@language{romanian}}
\@writefile{lof}{\select@language{romanian}}
\@writefile{lot}{\select@language{romanian}}
\select@language{romanian}
\@writefile{toc}{\select@language{romanian}}
\@writefile{lof}{\select@language{romanian}}
\@writefile{lot}{\select@language{romanian}}
\newacro{Ap\u a}[\AC@hyperlink{Ap\u a}{Ap\u a}]{f\u acut\u a din 3 elemente \tex
tcommabelow si 2 molecule}
\@writefile{toc}{\contentsline {chapter}{\numberline {1}Oscila\c {t}ii}{2}}
\@writefile{lof}{\addvspace {10\p@ }}
\@writefile{lot}{\addvspace {10\p@ }}

Note the aux file characters are never written as characters but using latex commands so they can be read back even if the file is using a different encoding at that point.

share|improve this answer
    
oops, i hurried and put things in different order. but, i hope you continue this question because this is exactly what i am doing, just as in .aux. so you understand: i take \immediate\read lines from plain-text templates, transform then and then format or do \immediate\writes (\newcommand) in a la .aux style, which i then \input back. But i also mix template with source, so i reached a \TeXnique for this. I will edit the question, although the MWE will work, and explain where it comes from. –  sjbiaga May 16 '12 at 19:28
    
If you are using \immediate\write\@auxout rather than \protected@write then you are probably not enablung LaTeX's protect mechanism and so will get "fragile command in moving argument" errors. –  David Carlisle May 16 '12 at 19:52
    
Why should i delete the .aux file? You mean the .aux file has \newacro with UTF-8 encoded args, and it is read back in a moment when \inputencoding{latin10} is active? How can i then intervene or anticipate? –  sjbiaga May 20 '12 at 11:14
    
You only need to delete the aux file once, after you have fixed the main file not to have the catcode changes. Because you disabled inputenc that way the aux file is corrupt and even if you fix the main file the old aux file is read in at the start of the document and will generate errors. So fix the main file, delete the aux (and toc and any other files written previously) then re-run and it should be OK. –  David Carlisle May 20 '12 at 11:54
    
I cannot fix the main file anymore. I reedited the MWE. If you please, comment out %\catcodeXYZ=ij lines in mwe.tex and have \protected@write in mwe.dtx instead: here, i do these the error i get, cannot fix it. (i delete .* files except \LaTeX source.) –  sjbiaga May 20 '12 at 14:05

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.