It works for me with
\addto\extrasenglish{\languageshorthands{ngerman}\useshorthands{"}}
Code:
\documentclass{scrartcl}
\usepackage[english,ngerman]{babel}
\addto\extrasenglish{\languageshorthands{ngerman}\useshorthands{"}}
\begin{document}
erster/""zweiter Teil \\
Bindestrich"=Wort
\selectlanguage{english}
first/""second part\\
Hyphen"=Word
\selectlanguage{ngerman}
erster/""zweiter Teil\\
Bindestrich"=Wort
\end{document}
I was able to find my own LyX-only solution as follows :
Step 1: create a custom class, using the method in this post. I thus created a file "course.cls" based on the book class and registered it in the LyX class database. See also this post to put the .cls anywhere in your hard drive.
Step 2: change your document class in LyX (Document->Settings->Document class)
Step 3: In course.cls, after \LoadClassWithOptions{...}, add
\usepackage{afterpackage}
\AfterPackage{inputenc}{
\PopDefaultHookLabel
\input{Path/To/My/Own/Preamble.tex}
\usepackage{docmute}
\docmute
}
The package afterpackage allows to execute a code right after the package inputenc is loaded, which is usually the third line of LyX automatic preamble, before LyX adds anything specific. Then you put your own preamble, and finally the docmute package discards the rest of the preamble.
This is the only solution that works. I tried to input a preamble then use docmute, the rest of LyX preamble is not discarded (it seems that the class has its own preamble which is the one affected by docmute).
This fact seems to also mess with some hooks, but adding \PopDefaultHookLabel solves that. You can then for example copy and paste your whole LyX preamble and modify it as you please. Be also careful that in doing so, some special characters like é è present in LyX preamble have to be replaced by their '{e} and `{e} counterparts.
Best Answer