I have a Python string which I want to \include
in a latex file. However, my string has an underscore character (_
), which needs to be converted into \_
(this is latex representation for _) before included.
If I do:
self.name = self.laser_comboBox.currentText() #Get name from a qt widget
latex_name = self.name.replace("_", r"\_") #Replacing _ for \_
print self.name
print latex_name
I'll get:
XXXXXX-YY\_SN2017060009
XXXXXX-YY\_SN2017060009
As, it can be seen, both variables got replaced. This means that the replace
method happened inplace. However if I do:
self.name = self.laser_comboBox.currentText() #Get name from a qt widget
latex_name = str(self.name).replace("_", r"\_") #Converting to str and then replacing _ for \_
print self.name
print latex_name
I'll get:
XXXXXX-YY_SN2017060009
XXXXXX-YY\_SN2017060009
This is something that puzzled me..I'd like to know why this is happening...