0

Dear Stackoverflow members. I have a problem with spaces between the words in Latex math mode. I have to write text in math mode because of the work I'm doing, and I already did the job. But the words are sooo tightly closed to each other. An example is as below :

It's the code in latex:

$>>> if ret is True:$\\

The output is something like: ifretisTrue

You see? Sooo close to each other. I need a kind of command to set the spaces between words for all the math equations throughout the entire document. I can't remove math mode or use \text{} or \textrm{} since there are too much lines to change..

I need a kind of settings before (begin{document}) to for example increase the whole spaces between words in math mode. Consider \ (single backslash) in $hi \ there$ that will create enough space... or \quad command... But I can't manually add these backslashes to all of my documentation. That's why I'm looking for a kind of setting to increase the space between words in math mode

Thanks in advance.

  • 5
    You can use \mathrm{if ret is True} or \text{if ret is True} if you load amsmath, or \mathit{} if you want italics. I'll see if I can find a duplicate question for this. – Marijn Apr 15 '20 at 19:19
  • 4
  • 1
    Hi thanks for replying. But, that's not a solution. I mentioned in my question that I'm looking for a kind of setting and \text{} won't solve my problem. – Mahdi Dor Emami Apr 15 '20 at 19:28
  • 2
    Are you sure this isn't an instance of the XY problem? Math mode is really not designed for words. What features of being in math mode do you need these words to have? – ronno Apr 15 '20 at 19:30
  • Ah yes, I see now that you mentioned the commands in your question, sorry. However, what you want is not really possible. You could make the space an active math character and insert a 'real' space, but this would interfere a lot with normal math typesetting and would probably make actual math (formulas etc.) very badly spaced. It would be best to add the proper commands to your code. Even if this is a lot of work then still the results will be much better than any workarounds. – Marijn Apr 15 '20 at 19:34
  • 3
    Also, your example looks a bit like programming code, possibly Python. If it is that then you should not use math mode at all, but instead use a source code formatting package such as listings or minted. – Marijn Apr 15 '20 at 19:36
  • These >>> plus a few other things were not shown correctly in simple mode, but were fine in math mode... Plus, some = symbols. Yes, it's a python programming cheat sheet stuff – Mahdi Dor Emami Apr 15 '20 at 20:48
  • I've tested both and they're great!! but the problem is that I'm done with my documentation. I really don't have the time to put another vast amount of time to fix environments. I just need a tiny settings thing for math mode for words to be detectable. – Mahdi Dor Emami Apr 15 '20 at 21:40
  • Maybe you can use \verb~>>>if ret is True:~? That gives normal word spacing and looks like code (because it has a monospaced font). With some smart find and replace in your editor it should be possible to change this easily. For example: replace $>>> with \verb~>>> and replace $\\ with ~\\, or use end of line characters, for example replace \n$ with \verb~ to start a verbatim block for each line that starts with an $. Note that the verbatim block ends with the ~ character in this case, so you need to make sure that this character does not occur in your code, – Marijn Apr 16 '20 at 07:28
  • or if it does, then choose a different delimiter for that specific line, for example \verb+>>>if ret is True:+. Of course in such lines the symbol + may not appear. You can also find and replace with \begin{verbatim} and \end{verbatim}, then you don't have to worry about delimiters. – Marijn Apr 16 '20 at 07:30

0 Answers0