0

I have started using pylatex four days ago to automate report generation (I have no earlier experience in latex as well). The text that I want to enter in the latex report has been generated by an online server and stored in my file as a text file. In the text file, there exist places with more than one simultaneous space for proper formatting and aligning (Protein Sequence Alignment). Hence, while simply trying to use .append, pylatex seems to ignore all the extra spaces on its own. I searched the internet with various relevant terms, but could not find any answer for pylatex. I did find some latex answers, exploring which I tried to incorporate pylatex's NoEscape and explicitly replacing " " (double spaces) with " \space ", it seems to work for some lines as expected, but not for others (maybe some of the places have \ (or some other special characters for latex) which are expected to be meaningful but could not understand what it actually means since it does not even exist (for example \clo). Can someone please suggest a method where I can simply allow the simultaneous existence of the spaces, which is also visible in the final document without the need to think about the existence of a possible special character that needs to be escaped. The following code snippets that I used might be of use to answer/understand my query.

i = 0
    with doc.create(Subsection('Details')):
        with open(whatcheck_detail, 'r') as fh:
            lines = fh.read().split("#")[1:]
            for line in lines:
                i += 1
                line = line.replace("  ", " \space ").replace("#", "\#") + "\n"
                if "Note:" in line:
                    print(i)
                    # doc.append(TextColor(line))
                    doc.append(NoEscape(line))
                elif "Warning:" in line:
                    print(i)
                    # line = "\color{blue} " + line
                    doc.append(NoEscape(line))
                    # doc.append(TextColor("blue", line))
                elif "Error:" in line:
                    print(i)
                    # line = "\color{red} " + line
                    doc.append(NoEscape(line))
                    # doc.append(TextColor("red", line))

And the following is the screenshot of the last part of the error report. Error Description upon running the above script.

Following are the images of what is happening by using the simple pylatex code doc.append(TextColor("color", line)), and what is actually in the text file (which is how I want it to be on PDF generated by latex/pylatex). What is happening to the text in the output file. What is in the text file, or how do I want it.

Thank you!

  • Note that there are specialized LaTeX packages to format sequence alignments. In particular this one: https://ctan.org/tex-archive/macros/latex/contrib/texshade/ Not sure how this can interplay with pylatex (I had never heard about pylatex). – bli Jul 25 '21 at 19:41
  • Are there any latex characters in the protein alignment? Could you just use `verbatim` tags and print the alignment as raw text? – Ghoti Jul 27 '21 at 18:19
  • Thank you @bli for your suggestion. Although the use of texshade could very well benefit me if implemented, at the present, it is beyond me to utilize it with PyLaTeX, however, I believe that I could learn it for future purposes as its features are highly relevant for me. – Abhishek Kumar Singh Jul 30 '21 at 15:49
  • Thank you @Ghoti for your suggestion as well. After multiple trials and different approaches by verbatim, I was able to implement what I wanted, although it is not so good looking because there seems to be extra "%" appearing at the start and the end of the paragraph no matter what I tried. Furthermore, I need to change the colours of some of the paragraphs, but I am not able to do that. Furthermore, the font style is different from the rest of the document and is not as elegant as the rest. Do you happen to have any suggestions regarding these problems? – Abhishek Kumar Singh Jul 30 '21 at 15:55
  • Maybe replace spaces with commands listed here: https://tex.stackexchange.com/questions/74353/what-commands-are-there-for-horizontal-spacing – Ghoti Jul 30 '21 at 17:36

0 Answers0