Formatting Python code

Paul A. Rubin parubin73 at gmail.com
Sat May 28 00:01:04 UTC 2022


On 5/27/22 18:44, Rich Shepard wrote:
> On Fri, 27 May 2022, Paul A. Rubin wrote:
>
>> AFAIK, \lstset{} is the correct command. In order to use it in the
>> preamble, you have to precede it with \usepackage{listings}.
>
> Paul,
>
> I overlooked that.
>
>> The correct syntax for setting the tabulator size is tabsize=4. 
>> "Tabulator
>> size=4" will cause an error.
>
> Okay. I wondered about that string.
>
>> Setting package defaults in the preamble will not register in the LyX
>> settings dialog, but they will work. So the dialog will continue to say
>> "no language" and tab size 4 (or whatever the dialog defaults are), but
>> your preamble settings will work in the compiled document.
>
> Good.
>
> Now I find an error in the complied document that makes no sense.
>
> In one code block are these lines:
> row_index_width = 100,
> auto_resize_default_row_index = True,
> set_all_heights_and_widths = False,
> row_height = "1",
>
> but in the PDF the middle two lines are combined and there are spaces 
> before
> the terminating commas:
> row_index_width = 100,
> auto_resize_default_row_index = True , set_all_heights_and_widths = 
> False ,
> row_height = "1",
>
> So far I've not been able to figure out why so I'll worry about this 
> tomorrow.
>
> Thanks,
>
> Rich
If the code was copied from outside LyX and pasted in, maybe there are 
some stray nonprinting characters and/or one of the supposed end-of-line 
characters is borked. The simplest way to test this would be to 
backspace over the offending commas and surrounding spaces and then type 
them back in.

Paul

PS: For future reference, a simple alternative to mucking around with 
package defaults is to create an empty listing inset, fiddle with 
options in the settings dialog, then just copy the empty inset and paste 
the copy in wherever you need to enter code.


More information about the lyx-users mailing list