0

When I integrated this How to use the standard - (hyphen) as the \hyp{} command from the hyphenat package? into my main document, I got errors about hyphen usage on translations packages:

Redoing nameref's sectioning
Redoing nameref's label
(D:\User\Documents\latex\texmfs\install\tex\latex\microtype\mt-cmr.cfg) (D:\User\Documents\latex\texmfs\install\tex\context\base\supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
) ABD: EverySelectfont initializing macros (D:\User\Documents\latex\texmfs\install\tex\latex\beamer\translator\dicts\translator-basic-dictionary\translator-basic-dictionary-English.dict
D:\User\Documents\latex\texmfs\install\tex\latex\beamer\translator\dicts\translator-basic-dictionary\translator-basic-dictionary-English.dict:2: Missing \endcsname inserted
D:\User\Documents\latex\texmfs\install\tex\latex\beamer\translator\dicts\translator-basic-dictionary\translator-basic-dictionary-English.dict:2:  ==> Fatal error occurred, no output PDF file produced!
Transcript written on D:\thesis\setup\cache\main.log.
gross execution time: 8855 ms
user mode: 8625 ms, kernel mode: 125 ms, total: 8750

... on main.log
Package lastpage Info: Please have a look at the pageslts package at
(lastpage)             https://www.ctan.org/pkg/pageslts
(lastpage)             ! on input line 332.
\c@lstlisting=\count631
 (D:\User\Documents\latex\texmfs\install\tex\latex\beamer\translator\dicts\translator-basic-dictionary\translator-basic-dictionary-English.dict
Dictionary: translator-basic-dictionary, Language: English 

D:\User\Documents\latex\texmfs\install\tex\latex\beamer\translator\dicts\translator-basic-dictionary\translator-basic-dictionary-English.dict:2: Missing \endcsname inserted 
Here is how much of TeX's memory you used:

Then, I included it like this in my document:

\begin{document}

    \ExplSyntaxOn
    \cs_new:Npn \hyphenfix_emdash:c {---}
    ...

    Tests.

    Encoding-encoding-encoding-encoding-encoding-encoding-encoding-encoding-encoding-encoding.

\end{document}

And it worked!

Is there a way to include it on my preamble instead of the start of my document?

Update

As suggested on comment, I added \AtBeginDocument{, but it did not work:

\usepackage{expl3}
\AtBeginDocument{%
    \ExplSyntaxOn
    \cs_new:Npn \hyphenfix_emdash:c {---}
    \cs_new:Npn \hyphenfix_endash:c {--}

    \cs_new:Npn \hyphenfix_discardnext:NN #1#2{#1}


    \catcode`\-=\active

    \cs_new_protected:Npn -{
        \futurelet\hyphenfix_nexttok\hyphenfix_i:w
    }

    \cs_new:Npn \hyphenfix_i:w {
        \cs_if_eq:NNTF{\hyphenfix_nexttok}{-}{
            %discard the next `-` token
            \hyphenfix_discardnext:NN{\futurelet\hyphenfix_nexttok\hyphenfix_ii:w}
        }{
            % from package hyphenat
            \hyp
        }
    }

    \cs_new:Npn \hyphenfix_ii:w {
        \cs_if_eq:NNTF{\hyphenfix_nexttok}{-}{
            \hyphenfix_discardnext:NN{\hyphenfix_emdash:c}
        }{
            \hyphenfix_endash:c
        }
    }
    \ExplSyntaxOff
}

Now, it throw another error:

Package microtype Info: Loading generic protrusion settings for font family
(microtype)             `pcr' (encoding: T1).
(microtype)             For optimal results, create family-specific settings.
(microtype)             See the microtype manual for details.
main.tex:333: Missing $ inserted 
Here is how much of TeX's memory you used:

On the line main.tex:333 I have \begin{document}.

  • In your preamble, \AtBeginDocument{\ExplSyntaxOn \cs_new:Npn \hyphenfix_emdash:c {---}....} – Steven B. Segletes Apr 26 at 0:11
  • I tried this but did not work. I updated the question with the details. – user Apr 26 at 0:21
  • Could I put this in a command and run it manually after \begin{document}? – user Apr 26 at 0:23
  • I am obviously not versed in xparse and will defer to the experts in L3. – Steven B. Segletes Apr 26 at 1:02
  • \ExplSyntaxOn and \ExplSyntaxOff must be outside the \AtBeginDocument. And also the \catcode command is too late inside the argument. – Ulrike Fischer Apr 26 at 6:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.