pytexutils.figures.image

 1def image(image_full_path : str, caption : str = "image_caption", label : str = "image_label", preamble : bool = False) -> str:
 2    '''
 3        Produces LaTeX code to display an image.  
 4
 5        Parameters:  
 6        -----------  
 7        - image_full_path : str  
 8            path of the image in the LaTeX project  
 9        - caption : str  
10            string for the caption of LaTeX table (default: "table_caption")  
11        - label : str  
12            string for the label of LaTeX table (default: "table_label")  
13        - preamble : bool  
14            If True the function will return a full LaTeX document, if False the function will return only the table (default: False)  
15
16        Returns:  
17        --------  
18        - p : str  
19            LaTeX code to display an image  
20        
21        Usage:
22        ------
23
24        ```python
25    
26        latex_table = image('fig1.png', caption='My image 1', label='img1', preamble=True)
27        ```
28
29        Output:
30        -------
31
32        ```latex
33        \\documentclass[11pt]{article}
34        \\usepackage{graphicx}
35        \\begin{document}
36
37        \\begin{figure}[!ht]
38                \\centering
39                \\includegraphics[width=\\columnwidth]{fig1.png}
40                \\caption{My image 1}\\label{fig:img1}
41        \\end{figure}
42
43        \\end{document}
44        ```
45    '''
46
47    p = ""
48    # LaTeX preamble
49    if preamble:
50        p += "\\documentclass[11pt]{article}\n"
51        p += "\\usepackage{graphicx}\n"
52        p += "\\begin{document}\n\n"
53        
54
55    # Table
56    p += "\\begin{figure}[!ht]\n"
57    p += "\t\\centering\n"
58    
59    p += "\t\\includegraphics[width=\\columnwidth]{"+str(image_full_path)+"}\n"
60
61    p += "\t\\caption{"+str(caption)+"}\\label{fig:"+label+"}\n"
62    p += "\\end{figure}\n"
63
64    if preamble:
65        # End document
66        p += "\n\\end{document}\n"
67
68    return p
def image( image_full_path: str, caption: str = 'image_caption', label: str = 'image_label', preamble: bool = False) -> str:
 2def image(image_full_path : str, caption : str = "image_caption", label : str = "image_label", preamble : bool = False) -> str:
 3    '''
 4        Produces LaTeX code to display an image.  
 5
 6        Parameters:  
 7        -----------  
 8        - image_full_path : str  
 9            path of the image in the LaTeX project  
10        - caption : str  
11            string for the caption of LaTeX table (default: "table_caption")  
12        - label : str  
13            string for the label of LaTeX table (default: "table_label")  
14        - preamble : bool  
15            If True the function will return a full LaTeX document, if False the function will return only the table (default: False)  
16
17        Returns:  
18        --------  
19        - p : str  
20            LaTeX code to display an image  
21        
22        Usage:
23        ------
24
25        ```python
26    
27        latex_table = image('fig1.png', caption='My image 1', label='img1', preamble=True)
28        ```
29
30        Output:
31        -------
32
33        ```latex
34        \\documentclass[11pt]{article}
35        \\usepackage{graphicx}
36        \\begin{document}
37
38        \\begin{figure}[!ht]
39                \\centering
40                \\includegraphics[width=\\columnwidth]{fig1.png}
41                \\caption{My image 1}\\label{fig:img1}
42        \\end{figure}
43
44        \\end{document}
45        ```
46    '''
47
48    p = ""
49    # LaTeX preamble
50    if preamble:
51        p += "\\documentclass[11pt]{article}\n"
52        p += "\\usepackage{graphicx}\n"
53        p += "\\begin{document}\n\n"
54        
55
56    # Table
57    p += "\\begin{figure}[!ht]\n"
58    p += "\t\\centering\n"
59    
60    p += "\t\\includegraphics[width=\\columnwidth]{"+str(image_full_path)+"}\n"
61
62    p += "\t\\caption{"+str(caption)+"}\\label{fig:"+label+"}\n"
63    p += "\\end{figure}\n"
64
65    if preamble:
66        # End document
67        p += "\n\\end{document}\n"
68
69    return p

Produces LaTeX code to display an image.

Parameters:

  • image_full_path : str
    path of the image in the LaTeX project
  • caption : str
    string for the caption of LaTeX table (default: "table_caption")
  • label : str
    string for the label of LaTeX table (default: "table_label")
  • preamble : bool
    If True the function will return a full LaTeX document, if False the function will return only the table (default: False)

Returns:

  • p : str
    LaTeX code to display an image

Usage:

latex_table = image('fig1.png', caption='My image 1', label='img1', preamble=True)

Output:

\documentclass[11pt]{article}
\usepackage{graphicx}
\begin{document}

\begin{figure}[!ht]
        \centering
        \includegraphics[width=\columnwidth]{fig1.png}
        \caption{My image 1}\label{fig:img1}
\end{figure}

\end{document}