I need to add ~ between a single letter word and another word so they don't get separated. When the letter and word is between \begin{verbatim} and \end{verbatim}, it should be ignored as that is source code that doesn't need white spaces.
Is there a good application or command line tool that can easily achieve this ?
Text Formatting ⇒ Automatically add white space
-
- Posts: 87
- Joined: Tue Sep 14, 2010 6:58 pm
Re: Automatically add white space
I'm not certain what is being asked here. Could you give an example?
If I understand, you want to automatically insert a ~ between two words, say "Donald" and "Knuth", so that every instance they appear, they will always be on the same line together.
If that is the case, could you not simply define your own command so that \dk inserts "Donald~Knuth" or do a search and replace? Again, perhaps I'm not understanding the problem.
If I understand, you want to automatically insert a ~ between two words, say "Donald" and "Knuth", so that every instance they appear, they will always be on the same line together.
If that is the case, could you not simply define your own command so that \dk inserts "Donald~Knuth" or do a search and replace? Again, perhaps I'm not understanding the problem.
Automatically add white space
I think the issue is that the source document is already written and SkyHiRider now wants to change something globally using a find and replace, e.g., change "Donald Knuth" everywhere to "Donald~Knuth" except where "Donald Knuth" appears inside a verbatim environment, which case it should be left as Donald Knuth.
Sure, this can be done in a variety of ways. For example, with sed:
That will take input.tex as input and substitute "Donald Knuth" with "Donald~Knuth" everywhere except between \begin{verbatim} and \end{verbatim}, and output a file named output.tex. (If you just want to alter input.tex without outputting a separate file -- be careful you know what you're doing! -- then put "-i" right after "sed" and leave out the "> output.tex" part.
But if you're not using a unix-based operating system, and don't have access to sed, I think I know how to do something similar with vim. If neither of those are options, certainly it could be done with something like perl. But why don't you tell us what operating system you are using?
Sure, this can be done in a variety of ways. For example, with sed:
Code: Select all
sed '/\\begin{verbatim}/,/\\end{verbatim}/ !s/Donald Knuth/Donald~Knuth/g' input.tex > output.tex
But if you're not using a unix-based operating system, and don't have access to sed, I think I know how to do something similar with vim. If neither of those are options, certainly it could be done with something like perl. But why don't you tell us what operating system you are using?