Is there a way to disable LyX's automatic insertion of \selectlanguage and \inputencoding? I like being able to switch languages by hand once in a while, but 99% of the times LyX inserts those commands automatically, it breaks my ERT hacking only since it thinks my opening { is English, while my closing } should be British, or something equally uninteresting. Today I had some cryptic error because LyX was switching between \inputencoding{latin1} and \inputencoding{latin9} (I prefer UTF8) and threw in a few braces in less than fortunate places...

I know I can solve issues caused by \selectlanguage by resetting language in the "text style" window. Is there a similar quick fix for \inputencoding I could use until I can disable its automatic insertion?

To be complete, I use:

Ubuntu 13.04

LyX 2.0.3 (2012-02-19)

Built on Jun 1 2012, 15:14:25

The following example is not exactly what I intended to ask before, but hopefully similar enough. In Lyx everything looks innocent:

#LyX 2.0 created this file. For more info see http://www.lyx.org/
\lyxformat 413
\textclass article
\use_default_options true
\maintain_unincluded_children false
\language english
\language_package none
\inputencoding default
\fontencoding global
\font_roman default
\font_sans default
\font_typewriter default
\font_default_family default
\use_non_tex_fonts false
\font_sc false
\font_osf false
\font_sf_scale 100
\font_tt_scale 100

\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\paperfontsize default
\spacing single
\use_hyperref false
\papersize a4paper
\use_geometry false
\use_amsmath 2
\use_esint 1
\use_mhchem 1
\use_mathdots 1
\cite_engine basic
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\use_refstyle 1
\index Index
\shortcut idx
\color #008000
\secnumdepth 3
\tocdepth 3
\paragraph_separation skip
\defskip medskip
\quotes_language english
\papercolumns 1
\papersides 1
\paperpagestyle default
\tracking_changes false
\output_changes false
\html_math_output 0
\html_css_as_file 0
\html_be_strict false


\begin_layout Standard


Now, after conversion to tex, with lyx --export pdflatex test.lyx, a suspicious \selectlanguage{english} appears:

%% LyX 2.0.3 created this file.  For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.




and indeed running pdflatex test.tex fails:

! Package babel Error: You haven't loaded the language english yet.

See the babel package documentation for explanation.
Type  H <return>  for immediate help.

l.23 \selectlanguage{english}


compiling the pdf from Lyx directly gives the same error.

  • I found the \inputencoding was inserted where the language was changed to 'LaTeX', so resetting the language fixes that too. – Roel Sep 11 '13 at 19:12
  • This thread describes the same behaviour: [comments.gmane.org/gmane.editors.lyx.general/62290]. I fixed my document before posting this question and I can't recall how I got into the situation, so unfortunately I can't post a minimal example – Roel Sep 14 '13 at 13:31

Go to

Document Settings > Language

Change Encoding to Other and select Language Default (no inputenc)`

For language package, select None.

[EDIT] After exporting your .lyx file with pdflatex I get the following, which does not have \selectlanguage{english} and which (as a result) compiles fine:

%% LyX 2.0.7dev created this file.  For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.



I tested on the development versions of LyX 2.0.x and LyX 2.1 beta. Thus, the problem must have been a bug in LyX that was fixed. Since you are on Ubuntu, it's very easy to use the latest stable version (and/or development version) without having to give up your current version. They can all be installed with no risk. To do this, see the instructions here: http://wiki.lyx.org/LyX/LyXOnUbuntu#toc3

  • 1
    I'm confused; I did what you suggested, but still see \selectlanguage in the LaTeX Source Preview. An exported *.tex file even has \usepackage{babel} in it. My issue about the automatic inclusion of those bits of code though, and I don't really know when that happens. I believe usually when pasting external text from the clip board, but I can't reproduce it reliably. – Roel Sep 11 '13 at 19:31
  • @Roel please see my comment regarding a minimal example. – scottkosty Sep 12 '13 at 15:16
  • I made one. It took a while since most of the time Lyx works very well :) – Roel Sep 14 '13 at 14:16
  • @Roel thanks for making the MWE. Yes, sometimes it can take time. But once it's done the answer often pops right out, like in this case. – scottkosty Sep 14 '13 at 17:54

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.