I am glad you found it useful and thank you so much for writing a comment. If you have time, please have a look at my LaTeX playlist on UA-cam since I have many other videos you may find useful. Like exporting a Pandas dataframe to a LaTeX table.
Hello there thanks for the video, its being so usefull, however I have two questions, If im running a project with multiple .tex files, once \var is defined on the main.tex, I get Undefined Control Secuence on the others, but somehow, it still works somethimes (yeah, fails in some cases), is there a need to remember the current .tex (sections/template.tex) the existance of \var? And the other one, can we use it to load images from it? I mean, save in a variable a image path, and then pass it to \includegraphics? For the tests I made, I didnt succeed, \var{img_path} remains green, like if \includegraphics treated it as a hole string, not as a variable. Could you please help me out, thanks!
Thanks Federico,this video is very useful. But I have a question, if I have a graph that I generate with python, can I export it to the LaTex document?
Hi. I want to show my code with colors etc like in a code editor in my latex doc. The code should not run or do anythong in the document, just stand like in a code editor. Thanks
Hi Federico, thank you very much for your tutorial. It has been very useful to me. However, I have a litter problem when I try to use the \var{key} entity inside a table. Can you help me to make work a table built from several \var{key} entities in its fields? thank in advance for any help
I use pycharm. I have a video on how to get started with pycharm and latex, and another video in which I explain how to setup pycharm to work with python
Thanks a lot for the tutorial. It worked totally fine. However, I tried to use the var command inside a for loop using the pgffor package and it didn't work. I think it has something to do with DTLloaddb returning a local variable and not a global one, but I could not figure out how to change the code to make everything global. I would be very happy if you have any tips. Thanks again!
@@FedericoTartarini Thanks for trying to help! I'm doing a for loop inside latex to insert some images and I need that the caption of each image states some data generated by my python code. As a final solution, I can abadon the for loop in latex and write all the figure environments using python, but I think a solution inside Latex would be better
Yes, I think that it would be easier if you create a .tex file with python that imports the figure and the captions. Then in latex you can just import that file using the \input{} command. At this stage I would not know if you can solve the problem you are facing with the for loop. Sorry for that.
Great tutorial, thank you! But what do you think about running python inside LaTex with PythonTeX or PyLuaTeX? Wouldn't it be even better, and wouldn't it give even more features?
I am looking into PythonTeX and in general, unless you are teaching, I am against embedding Python code into LaTeX since that can make your project very messy. I prefer to have my python and latex separate.
Hi, Dr. Tartarini. Thanks for making this video! I'm using overleaf to compile and getting a few errors. The first is "Package filecontents Warning: This package is obsolete. Disabling it and passing control to the filecontents environment defined by the LaTeX kernel." The second is "Runaway argument?" on line 120. Line 119 is " ewcommand{\testingtesting}[1]{\DTLfetch{mydata}{thekey}{#1}{thevalue}}", and line 120 is a blank line after 119. I suspect that passing control to the filecontents environment defined by the LaTeX kernel is causing the compiler to not handle line 119 properly. In any case, do you have advice? Thanks again! Edit: I figured it out! mydata.dat had a "maxdiff,0.92%" in it. the "%" was causing issues. Thanks again for the video!
Thanks a lot for video! Is it real to make it in Word? Create document with data as result of working my program and export variables to Word document. And when I will change my program and get new data, variables automatically will change in document.
Hi I'm trying to write a python variable in the format #,### to the mydata.dat file, however I think there is an issue with the separator in the format. Can you help with a work around?
@@FedericoTartariniI have followed all the steps. I have defined the save_var_latex function as you did and have tried the following lines: save_var_latex('test_val1', '1234') save_var_latex('test_val2', '6789') These both work fine and when i check the newly created mydata file i can see both entries. However, when I run the following lines: save_var_latex('test_val3', '1,234') save_var_latex('test_val4, '6,789') I have an issue. Opening up the mydata file I can see the keys but the values haven't been written correctly, I'm assuming it doesn't like the "," separator in the numbers 1234 & 6789. I have tried to use a different delimiter, but I still have issues, the datafile now shows the following: test_val3|1|234 test_val4|6,789 Which is not what I was expecting. Appreciate any help you can give.
Hi Jordan, thank you for sharing more info on this. Yes, the issue is caused by the fact that there is a comma in your numbers, this causes an issue with both the separator and the fact that inputs in functions are separated by a comma. You can fix the problem by using the following code, which uses | as a separator. Please note that you will have to pass the number into the Python function as a string. ```python def save_var_latex(key, value): import csv import os dict_var = {} file_path = os.path.join(os.getcwd(), "mydata.dat") try: with open(file_path, newline="") as file: reader = csv.reader(file, delimiter ='|') for row in reader: dict_var[row[0]] = row[1] except FileNotFoundError: pass dict_var[key] = value with open(file_path, "w") as f: for key in dict_var.keys(): f.write(f"{key}|{dict_var[key]} ") save_var_latex("x", "6,38") ``` ```latex % package to open file containing variables \usepackage{datatool, filecontents} \DTLsetseparator{|}% Set the separator between the columns. % import data \DTLloaddb[noheader, keys={thekey,thevalue}]{mydata}{../mydata.dat} % Loads mydata.dat with column headers 'thekey' and 'thevalue'
Thank you so much for letting me know and for writing a comment. I am glad that you found my video useful. If you can, please share the video with friends and colleagues who may find it useful. Have a great day.
Great tutorial, clear explanation & easy to follow. Thanks for your video
Glad it was helpful!
It was really helpful. I am now implementing these tools in my research's package. Definitely It will save a lot of time. Thank you Federico!
I am glad you found it useful and thank you so much for writing a comment. If you have time, please have a look at my LaTeX playlist on UA-cam since I have many other videos you may find useful. Like exporting a Pandas dataframe to a LaTeX table.
Nice video. Looking at generating some dynamic formatted images using LaTeX and I'm new to it, this was a quick watch with a lot of good info. Thanks!
Great to hear!
Nice contribution. Thanks for the tutorial
Wonderful video, it was just what I needed
Great to hear that. Thank you
Gracias! Se puede implementar esto en Overleaf?
Yes, you can kind of do that by connecting overleaf with GitHub. I have a video on that if you want to learn how to sync the two
Hello there thanks for the video, its being so usefull, however I have two questions, If im running a project with multiple .tex files, once \var is defined on the main.tex, I get Undefined Control Secuence on the others, but somehow, it still works somethimes (yeah, fails in some cases), is there a need to remember the current .tex (sections/template.tex) the existance of \var?
And the other one, can we use it to load images from it? I mean, save in a variable a image path, and then pass it to \includegraphics? For the tests I made, I didnt succeed, \var{img_path} remains green, like if \includegraphics treated it as a hole string, not as a variable.
Could you please help me out, thanks!
Thanks Federico,this video is very useful.
But I have a question, if I have a graph that I generate with python, can I export it to the LaTex document?
Yes, of course. You can save it as a PNG and import it into python
Thanks Federico, this is very useful. Is there any way to do the same within a jupyter notebook?Thanks
Sure you can do that in a Jupiter notebook as long as the notebook can save a file in your computer.
Hi. I want to show my code with colors etc like in a code editor in my latex doc. The code should not run or do anythong in the document, just stand like in a code editor. Thanks
Hi, you can follow this guide: www.overleaf.com/learn/latex/Code_listing.
I am planning to release a video about this topic soon.
Hi Federico, thank you very much for your tutorial. It has been very useful to me. However, I have a litter problem when I try to use the \var{key} entity inside a table. Can you help me to make work a table built from several \var{key} entities in its fields? thank in advance for any help
Please share the code with me.
Hi!! What app are you using for compile all this?
I use pycharm. I have a video on how to get started with pycharm and latex, and another video in which I explain how to setup pycharm to work with python
@@FedericoTartarini Thank you! You are my new idol!!
Thank you so much. Let me know if you have any other questions and please check my LaTeX playlist. I am sure you will find some of the videos useful.
Thanks a lot for the tutorial. It worked totally fine. However, I tried to use the var command inside a for loop using the pgffor package and it didn't work. I think it has something to do with DTLloaddb returning a local variable and not a global one, but I could not figure out how to change the code to make everything global. I would be very happy if you have any tips. Thanks again!
Hi, unfortunately I have never tried to use it inside a for loop. What are you trying to do? Maybe there is another solution to solve the problem.
@@FedericoTartarini Thanks for trying to help! I'm doing a for loop inside latex to insert some images and I need that the caption of each image states some data generated by my python code. As a final solution, I can abadon the for loop in latex and write all the figure environments using python, but I think a solution inside Latex would be better
Yes, I think that it would be easier if you create a .tex file with python that imports the figure and the captions. Then in latex you can just import that file using the \input{} command. At this stage I would not know if you can solve the problem you are facing with the for loop. Sorry for that.
great tutorial. it helped me so much
thank you!!
Thank you for letting me know. I am glad you found it useful.
Great tutorial, thank you!
But what do you think about running python inside LaTex with PythonTeX or PyLuaTeX? Wouldn't it be even better, and wouldn't it give even more features?
Thank you very much. I have never tried those packages. I'll look into it.
I am looking into PythonTeX and in general, unless you are teaching, I am against embedding Python code into LaTeX since that can make your project very messy. I prefer to have my python and latex separate.
Very helpfull :)
Thank you very much.
Hi, Dr. Tartarini. Thanks for making this video! I'm using overleaf to compile and getting a few errors. The first is "Package filecontents Warning: This package is obsolete. Disabling it and passing control to the filecontents environment defined by the LaTeX kernel." The second is "Runaway argument?" on line 120. Line 119 is "
ewcommand{\testingtesting}[1]{\DTLfetch{mydata}{thekey}{#1}{thevalue}}", and line 120 is a blank line after 119. I suspect that passing control to the filecontents environment defined by the LaTeX kernel is causing the compiler to not handle line 119 properly. In any case, do you have advice? Thanks again!
Edit: I figured it out! mydata.dat had a "maxdiff,0.92%" in it. the "%" was causing issues. Thanks again for the video!
Actually, I figured it out! mydata.dat had a "maxdiff,0.92%" in it. the "%" was causing issues.
Great that you were able to solve all the problems
Thank you indeed.
You are very welcome
Thanks a lot for video! Is it real to make it in Word? Create document with data as result of working my program and export variables to Word document. And when I will change my program and get new data, variables automatically will change in document.
Hi, I am glad you liked the video. Thank you for leaving a comment. I am sorry but I did not understand your question
Hi I'm trying to write a python variable in the format #,### to the mydata.dat file, however I think there is an issue with the separator in the format. Can you help with a work around?
Could you please share more information about the error. Have you followed all the steps as shown in the video?
@@FedericoTartariniI have followed all the steps.
I have defined the save_var_latex function as you did and have tried the following lines:
save_var_latex('test_val1', '1234')
save_var_latex('test_val2', '6789')
These both work fine and when i check the newly created mydata file i can see both entries.
However, when I run the following lines:
save_var_latex('test_val3', '1,234')
save_var_latex('test_val4, '6,789')
I have an issue. Opening up the mydata file I can see the keys but the values haven't been written correctly, I'm assuming it doesn't like the "," separator in the numbers 1234 & 6789.
I have tried to use a different delimiter, but I still have issues, the datafile now shows the following:
test_val3|1|234
test_val4|6,789
Which is not what I was expecting.
Appreciate any help you can give.
Hi Jordan, thank you for sharing more info on this. Yes, the issue is caused by the fact that there is a comma in your numbers, this causes an issue with both the separator and the fact that inputs in functions are separated by a comma. You can fix the problem by using the following code, which uses | as a separator. Please note that you will have to pass the number into the Python function as a string.
```python
def save_var_latex(key, value):
import csv
import os
dict_var = {}
file_path = os.path.join(os.getcwd(), "mydata.dat")
try:
with open(file_path, newline="") as file:
reader = csv.reader(file, delimiter ='|')
for row in reader:
dict_var[row[0]] = row[1]
except FileNotFoundError:
pass
dict_var[key] = value
with open(file_path, "w") as f:
for key in dict_var.keys():
f.write(f"{key}|{dict_var[key]}
")
save_var_latex("x", "6,38")
```
```latex
% package to open file containing variables
\usepackage{datatool, filecontents}
\DTLsetseparator{|}% Set the separator between the columns.
% import data
\DTLloaddb[noheader, keys={thekey,thevalue}]{mydata}{../mydata.dat}
% Loads mydata.dat with column headers 'thekey' and 'thevalue'
ewcommand{\var}[1]{\DTLfetch{mydata}{thekey}{#1}{thevalue}}
```
@@FedericoTartarini Perfect that works! I was so close with my attempt to correct this - I had missed the ", delimiter = "|" " part in line 10.
Thanks a lot for the video amico
Thank you so much for letting me know and for writing a comment. I am glad that you found my video useful. If you can, please share the video with friends and colleagues who may find it useful. Have a great day.
Really good thx.
Thank you for letting me know.