Remaining issues

So we did this beforeCustomized ChemFig chemical conversion Python service image based on TexLiveAlthough the transformation of PDF output service has been completed, the output effect is not very good, as shown in the figure below:



There are two serious problems with this diagram

  • Chinese language not supported
  • White space is too large, paper space waste

In fact, the main problem is that it is hard for users to accept it, because it does not display well on the front end, and it is hard for them to read it. However, when I first touch latex, I feel helpless, so I support a silly paper change function. The PDF preview link to mol2Chemfig’s Web Interface on their website shows the PDF as a small piece with no white space, which is very nice. Then do some research and record the process of solving these two problems and the problems encountered

Solve Problems in Chinese

We choose the macro package CJKutf8, this macro package does not need to install anything else, it is also more convenient to use, Tex file modified as follows:

\documentclass{minimal}
\usepackage{xcolor, mol2chemfig}
\usepackage[a5paper, margin=10px, total={6in, 8in}]{geometry}
\usepackage{CJKutf8}
\usepackage[helvet]{sfmath}
\setcrambond0.4 pt 2.5 pt {} {} {} 1.0 pt\setbondoffset{1pt}
\setdoublesep{2pt}
\setatomsep{%(atomsep)spt}
\renewcommand{\printatom} [1] {\fontsize{8pt}{10pt}\selectfont{\ensuremath{\mathsf{# 1}}}}
\setlength{\parindent}{0pt}
\setlength{\fboxsep}{0pt}
\begin{document}
\begin{CJK}{UTF8}{gbsn}

\chemfig{H_3C-[:30]N**6(-(=O)-(**5(-N(-CH_3)--N-))--N(-CH_3)-(=O)-)}

\end{CJK}
\end{document}
Copy the code

Look at the effect with complex molecular formula. The rendering effect with A3paper (A4 can’t fit) :Our Chinese was successful, but the blank space was still too big to use

Remove white space

standalone

I have to say that there are very few Chinese documents for Latex. I can only search for them in Google, but I found them in English: ctan.org/pkg/standal… The text reads as follows:

Standalone -- Compile TEX pictures stand-alone or as part of a document a class and package is provided which allows TEX pictures or other TEX code to be compiled standalone or as part of a main document. Special support for pictures with beamer overlays is also provided. The package is used in the main document and skips extra preambles in sub-files. The class may be used to simplify the preamble in sub-files. By default the preview package is used to display the typeset code without margins. The behaviour in standalone mode may adjusted using a configuration file standalone.cfg to redefine the standalone environment.Copy the code

Key statements: By default the preview package is used to display the typeset code without margins This is exactly what we want, \ documentClass {standalone}

\documentclass{standalone}... ... ...Copy the code

Let’s look at the effect again using the small chemical formula:



There is no change, and there are a bunch of pt characters on the side, which should be caused by introducing the CJKutf8 macro package

Remove geometry and modify the style

The problem with using paper was that I used the Geometry macro package and set a5paper as the default paper, so we re-edited the Tex template file

\documentclass{standalone}
\usepackage{mol2chemfig}
\usepackage{CJKutf8}
\usepackage[helvet]{sfmath}
\begin{document}
\begin{CJK}{UTF8}{gbsn}

\chemfig{H_3C-[:30]N**6(-(=O)-(**5(-N(-CH_3)--N-))--N(-CH_3)-(=O)-)}

\end{CJK}
\end{document}

Copy the code

Let’s look at the effect:



The image is smaller, but the newline doesn’t work, and the image is topped with a border

Solve the newline problem

Use varWidth to solve the newline problem

Google latex standalone newline, the first record:Tex.stackexchange.com/questions/4…Varwidth: varWidth: varWidth: varWidth: varWidth: varWidth: varWidth: varWidth: varWidth: varWidth: varWidth



Almost perfect! Let’s try the big formula again, and it works like this:



Isn’t that the size of a5paper? Does varWidth only support a5 sizes? Is standalone also the default set of A5paper? We said to go to blank adaptive, how to cut the picture? Is it going in the wrong direction? Am I back where I started? I cracked!!

Solve the problem of missing pictures

By default, varWidth is 824x543px and the default width is \ lineWidth. We recommend using \maxdimen. Let’s optimize the Tex template again

\documentclass[margin=3mm,varwidth=\maxdimen]{standalone}
\usepackage{mol2chemfig}
\usepackage{CJKutf8}
\usepackage[helvet]{sfmath}
\begin{document}
\begin{CJK}{UTF8}{gbsn}
\begin{center}

\chemfig{H_3C-[:30]N**6(-(=O)-(**5(-N(-CH_3)--N-))--N(-CH_3)-(=O)-)}

\end{center}
\end{CJK}
\end{document}
Copy the code

Let’s look at the effect:

Prefect! So Prefect!

Refer to the link

Standalone:ctan.org/pkg/standal… LaTex supports Chinese in three ways: blog.csdn.net/z_feng12489… New line in standalone:tex.stackexchange.com/questions/4… Standalone: varwidth option limits the output width:tex.stackexchange.com/questions/9…