2

When converting a LyX document to a TeX file, I've noticed that the resulting code is not formatted in a "pretty" way. For example, when writing my own documents in LaTeX, I will tab lines with equations in them:

Here is an equation:
     \[
          r^2 = x^2 + y^2
     \]
That was an equation.

whereas the file output by LyX has no tabbing:

Here is an equation:
\[
r^2 = x^2 + y^2
\]
That was an equation.

I was wondering if there is a way to tell Lyx to do this automatically, so that when I export a LyX file to a LaTeX document I don't have to go back and tab every equation myself. In general, this applies to other cases as well, such as enumerate or itemize.

In summary: Can I control the "format" of the code in the TeX file that LyX outputs?

In case it is relevant: I am using LyX 2.3.2 on Ubuntu 18.04.01 LTS.

  • 1
    Welcome! Unfortunately, I don't think it's currently possible with LyX. It would indeed be nice to have prettier LaTeX output, but LyX does not focus on that. – scottkosty Feb 05 '19 at 05:35
  • I wonder what LyX uses to convert from LyX to TeX? Assuming it's some kind of script, I imagine I'd have to go in and edit the script, which seems beyond my abilities. – concertpi Feb 05 '19 at 06:49
  • One possibility is to tell your latex editor to format the LyX output. In Emacs with AUCTeX, there is a menu item in the LaTeX menu called "Format environment", which will format the current environment (so where the cursor is), and it will format the whole document if the environment is the document one. The actual Emacs command is M-x LaTeX-fill-environment. – Máté Wierdl Feb 05 '19 at 20:09
  • @concertpi A lot of the LaTeX is hardcoded in the C++ source files. Because of all kinds of interactions (packages clashing, commands depending on encoding, language, etc.), from what I understand, this hardcoding would be difficult to avoid. There is also a lot of LaTeX code handled by the layout mechanism. For more information, see Help > Customization. However, that is more about which LaTeX commands are used, not e.g., whitespace. – scottkosty Feb 05 '19 at 23:18
  • @MátéWierdl Although I would have to contend with the difficult learning curve of Emacs, I think this is a suitable solution. Would you care to post it as an answer? – concertpi Feb 08 '19 at 15:42
  • 1
    @concertpi, I think this website does what you want. There is also a discussion of this stuff here at StackExchange too, and they recommend the program latexindent. – Máté Wierdl Feb 09 '19 at 16:41
  • @MátéWierdl I think this settles the matter. While LyX will not allow me to format TeX files directly, there are "beautifying" plugins in other applications (or other scripts, etc) that will allow me to get the end result I desire. – concertpi Feb 18 '19 at 12:40
  • @concertpi Thanks! You should post that as the answer to this question. It seems to be the BEST way around the problem. I am only using lyx because I am being FORCED to. The more I use lyx the more convinced I am it is a piece of trash. – deps_stats Feb 11 '20 at 20:39

0 Answers0