pytexutils.utils.writer

 1from tkinter import filedialog
 2import os
 3
 4def write_to_file(content : str, path : str = None) -> None:
 5    '''
 6       Saves latex produced using pytexutils code to a file.
 7
 8        Parameters:  
 9        -----------  
10        - conntent : str:
11            latex code procude using pytexutils to be saved
12        - path : sting
13            path where to save the file, whitout extension (default : None), if None a filedialog will pop up to ask for the save path.
14                
15        Returns:  
16        --------  
17        Nothing the file will be saved
18        
19        Usage:
20        ------
21
22        ```python
23            latex_code =  "\\documentclass[11pt]{article}\n\\usepackage{graphicx}\n\\begin{document}\n\\begin{figure}[!ht]\n\\centering\n
24            \\includegraphics[width=\\columnwidth]{fig1.png}\n\\caption{My image 1}\\label{fig:img1}\n\\end{figure}\n\\end{document}"
25
26            write_to_file('path/')
27        ```
28
29        Output:
30        -------
31        Nothing, the file will be saved.
32    '''
33     
34    if path is not None:
35        os.makedirs(path, exist_ok=True)
36    else:
37        path = filedialog.askdirectory()
38        if path is None: raise Exception("Error Message: path not defined")
39    
40    with open(os.path.join(path,'pytexutils.tex'), 'w') as texfile:
41        texfile.writelines(content)
def write_to_file(content: str, path: str = None) -> None:
 5def write_to_file(content : str, path : str = None) -> None:
 6    '''
 7       Saves latex produced using pytexutils code to a file.
 8
 9        Parameters:  
10        -----------  
11        - conntent : str:
12            latex code procude using pytexutils to be saved
13        - path : sting
14            path where to save the file, whitout extension (default : None), if None a filedialog will pop up to ask for the save path.
15                
16        Returns:  
17        --------  
18        Nothing the file will be saved
19        
20        Usage:
21        ------
22
23        ```python
24            latex_code =  "\\documentclass[11pt]{article}\n\\usepackage{graphicx}\n\\begin{document}\n\\begin{figure}[!ht]\n\\centering\n
25            \\includegraphics[width=\\columnwidth]{fig1.png}\n\\caption{My image 1}\\label{fig:img1}\n\\end{figure}\n\\end{document}"
26
27            write_to_file('path/')
28        ```
29
30        Output:
31        -------
32        Nothing, the file will be saved.
33    '''
34     
35    if path is not None:
36        os.makedirs(path, exist_ok=True)
37    else:
38        path = filedialog.askdirectory()
39        if path is None: raise Exception("Error Message: path not defined")
40    
41    with open(os.path.join(path,'pytexutils.tex'), 'w') as texfile:
42        texfile.writelines(content)

Saves latex produced using pytexutils code to a file.

    Parameters:  
    -----------  
    - conntent : str:
        latex code procude using pytexutils to be saved
    - path : sting
        path where to save the file, whitout extension (default : None), if None a filedialog will pop up to ask for the save path.

    Returns:  
    --------  
    Nothing the file will be saved

    Usage:
    ------
    <div class="pdoc-code codehilite">
    <pre><span></span><code>            <span class="n">latex_code</span> <span class="o">=</span>  <span class="s2">&quot;\documentclass[11pt]</span><span class="si">{article}</span>
    \<span class="n">usepackage</span><span class="p">{</span><span class="n">graphicx</span><span class="p">}</span>
    \<span class="n">begin</span><span class="p">{</span><span class="n">document</span><span class="p">}</span>
    \<span class="n">begin</span><span class="p">{</span><span class="n">figure</span><span class="p">}[</span><span class="err">!</span><span class="n">ht</span><span class="p">]</span>
    \<span class="n">centering</span>
    
                \<span class="n">includegraphics</span><span class="p">[</span><span class="n">width</span><span class="o">=</span>\<span class="n">columnwidth</span><span class="p">]{</span><span class="n">fig1</span><span class="o">.</span><span class="n">png</span><span class="p">}</span>
    \<span class="n">caption</span><span class="p">{</span><span class="n">My</span> <span class="n">image</span> <span class="mi">1</span><span class="p">}</span>\<span class="n">label</span><span class="p">{</span><span class="n">fig</span><span class="p">:</span><span class="n">img1</span><span class="p">}</span>
    \<span class="n">end</span><span class="p">{</span><span class="n">figure</span><span class="p">}</span>
    \<span class="n">end</span><span class="p">{</span><span class="n">document</span><span class="p">}</span><span class="s2">&quot;</span>
    
                <span class="n">write_to_file</span><span class="p">(</span><span class="s1">&#39;path/&#39;</span><span class="p">)</span>
    </code></pre>
    </div>


    Output:
    -------
    Nothing, the file will be saved.