0

I wrote an introduction note about python, which included something like the following

...
\usepackage{pythonhighlight}
...
the following indentation works in python
\begin{python}
a=5
if a==4:
    print(a)
elif a==5:
    print(a-1)
\end{python}
and removing the indentation leads to an error
\begin{python}
a=5
if a==4:
print(a)
elif a==5:
print(a-1)
\end{python}

When I compiled for the first time, the pdf had all the indentations that I wanted.

However, after I completed the note and distributed, I get questions about what I mean here. After check the latex file, I surprisingly found that all the indentation in the latex file get lost. So the above code becomes

...
\usepackage{pythonhighlight}
...
the following indentation works in python
\begin{python}
a=5
if a==4:
print(a)
elif a==5:
print(a-1)
\end{python}
and removing the indentation leads to an error
\begin{python}
a=5
if a==4:
print(a)
elif a==5:
print(a-1)
\end{python}

I, of course, didn't do anything. I am wondering what could be a potential reason for that. Could it be a hotkey combination that I accidentally touched? For your information, I use TeXstudio.

8
  • Was the indentation lost before or after submission? If the latter, it seems to be a problem with the journal‘s side. If the former, I think indentation is lost is many editors if you select all contents and press shift-tab several times. Commented Jan 12 at 9:03
  • @JasperHabicht Thanks for your information. It is not a journal article. Besides, only the indents within the \begin{python}...\end{python} get lost. So it is unlikely that I accidentally selected many blocks of codes and hitted shift+tab. It should be something related to the package pythonhighlight. Commented Jan 12 at 9:20
  • I am wondering at which moment the indentation got lost. If I understand correctly, the indentation in your .tex file is gone. But no LaTeX package I know would manipulate the code in the .tex file directly. Maybe you activated something like “auto-indentation” which some editors provide for. Having different programming languages in the same document, this might have gone wrong. Commented Jan 12 at 11:28
  • I don’t know the package pythonhighlight but I doubt that it messes with indentation of the source code not only because this would not be what a LaTeX package should do, but especially because it was exactly written for highlighting Python code where indentation is an important part of the syntax. Looking at the code of the package it only seems to define some styles for highlighting with the listings package. Commented Jan 12 at 11:32
  • @JasperHabicht Thanks very much for the comments. The statement that "it should be related to the python package pythonhighlight" is only an educated guess based on that only indentation in \begin{python}...\end{python} is lost. Commented Jan 12 at 12:42

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.