I want to write a backslash character to a text file using LaTeX.
The first line of code below declares a variable 'file' which describes the file 'myfile.out'. The second line opens the file and the third one tries do write a backslash '\' to the file.
\documentclass{article}
\begin{document}
\newwrite\file%
\immediate\openout\file=myfile.out%
\immediate\write\file{\}%
\end{document}
The third line does not work because LaTeX get confused with the backslash, anyone knows how can I make it work? I tried a lot of things including \textbackslash, $\backslash$ \char ``\` etc and nothing seems to work.
Thanks a lot
Sound like you want a backslash in text mode; since \backslash does not work, try \textbackslash.
EDIT: \symbol{92} should also work.
You can use \#backslashchar. The following works for me:
\documentclass{article}
\begin{document}
\newwrite\file
\immediate\openout\file=myfile.out
\makeatletter
\immediate\write\file{\#backslashchar}
\makeatother
\closeout\file
\end{document}
"AB/FQS/ET004/2014" write it in latex with space as "AB/ FQS/ ET004/ 2014"
Related
I cannot get indented code to highlight in GAWK in vim markdown model
Context: I doing some literature programming in gawk. Comments are markdown syntax and code is GAWK, indented by a tab spaces.
Problem: I followed the doc at https://github.com/plasticboy/vim-markdown#options. The markdown highlights as it should but the indented code remains white and bland:
What I did: The first line of my source code is
# vim: nospell filetype=markdown :
My .vimrc contains the line
let g:vim_markdown_fenced_languages = ['awk=awk']
Which, according to the doc at SHOULD be enough to make that syntax highlight happen
Help?
That information is not enough to get vim to understand how to highlight your block of code. "Fenced" refers to code that is bounded by triple backticks as follows:
```awk
this is some awk code that would be highlighted
```
This, when combined with the let g:vim_markdown_fenced_languages = ['awk', 'sh', 'make'] etc lists, lets vim know exactly which highlighting syntax to use in a particular block.
You should also note that you don't need that particular vim plugin to get this to work; this is native vim functionality.
Edit: If you really want indentation, you can just indent the code block with the fencing:
```awk
some awk code surrounded by indented fencing would be highlighted
```
If you were really hard-pressed to avoid the fencing entirely, the only way I know of would be to go into the actual vim syntax files:
cd $(vim -Nesc '!echo $VIMRUNTIME' -c qa)
vim syntax/markdown.vim
and try to figure out a way to force a default of awk highlighting on indented code, but I wouldn't recommend it.
I inherited a script I want to refactor.
for some reason the script is intended with four whitespaces.
I would like to remove leading four whitespaces from each line.
Is there any handy and fast way to do it?
Message "Try to get Package Lock..."
if waitForPackageLock("300","false")
comment "UCS: Extra check if package lock is available."
endif
Cheers
That was a difficult one.
sed 's/^ //'
Or edit your script with an editor.
vim file
:%<
: execute a command
% apply to all lines
< remove one indent
Context
I am thinking I can solve a problem with the proper creation of a *.bat file.
I am automating a process in a backup program called Acronis Backup and Recovery.
I am able to make a script (jScript) that creates all the syntax except for one part correctly.
In a normal command prompt the command I would run looks like this
acrocmd backup file --include="C:\documents\Gale_thesis.doc" "D:\Sandbox\!oDC!-IMG_0222.MOV" "C:\temp\magnifyReader" --loc="D:\backups" --arc="Backup1a"
The jScript I am creating can generate this with no problem and save as a *.bat file. This can works perfect if my file names are clean. By clean I mean no characters the batch files think are key words and commands.
Anytime I have a word like “copy” or a character like “!” in a file name it fails.
Question
So I am now wondering if loading variables from a text file would do the trick?
I am sure a lot of readers know that when load multiple file/folder paths at the command line you need to surround them with double quotes.
So I need this variable to have the correct syntax to be parsed by the batch file and work like the example when I type it directly at a command prompt.
I had tried to follow info about using for /f etc.
But the examples are not broad enough for me to understand, nobody seems to explain how to use these variables mixed in with other syntax.
I know a little about working with variable in a *.bat file. My jScript application can produce the text in any format a list, escaped, what ever is needed.
Thanks
I might suggest you to take a look at escaping characters
http://www.robvanderwoude.com/escapechars.php
in for loops !var! is used when delayedexpansion is enabled so you might need to escape it
I used the following code provided by Aacini to test the arguments that are being passed
#echo off
setlocal enabledelayedexpansion
set argCount=0
for %%x in (%*) do (
set /A argCount+=1
set "argVec[!argCount!]=%%~x"
)
echo Number of processed arguments: %argCount%
and since delayedexpansion is enabled I had to escape ! character
arg.bat --include="C:\documents\Gale_thesis.doc" "D:\Sandbox\^^^!oDC^^^!-IMG_0222.MOV" "C:\temp\magnifyReader" --loc="D:\backups" --arc="Backup1a"
Also about the triple escape quotes ^^^
the problem here is that we need to pass two special characters,
1st is the up arrow ^ and 2nd is the exclamation mark !
so the 2nd batch file (the one that reads our arguments) should get ^!
to escape ^ we use ^^ and to escape ! we use ^!
Thanks to Aacini for his code in HERE
I have a SQL Server database extract I'm doing.
At the beginning of my program, I have:
ini_set('mssql.charset','cp1250');
My database calls do not do anything special.
I'm only call the following methods:
mssql_connect, mssql_select_db, mssql_query, mssql_fetch_object,
mssql_next_result and mssql_close.
When I print the output of my export on screen, all the characters look fine. When I export fputcsv() into a csv file, I get a ton of <92> and <93> characters (this is the way that they look when I use a terminal to read them). When I open the file using Excel, they look like ì, í and î
This is causing major problems. Do you have any ideas?
try to convert encoding into utf8
iconv('cp1250', 'utf-8', $text);
also print this:
var_dump(iconv_get_encoding('all'));
Thanks but it turns out that the problem isn't with the encoding so much as it is with the fact that my fputcsv() call actually was not specifying a delimiter. I chose "\t" for the delim and everything worked perfectly.
I would like to reformat some code which looks like this :
if (cond) {
foo;
}
to
if (cond)
{
foo;
}
Since this is C code, I have been looking at cindent/cinoptions to use with = but it seems it does not deal with multiline rules.
I have been looking at formatoptionsto use with gq, and it does not seem to be possible either.
So is it possible using default Vim options or should I use a specific plugin or function ?
:%s/^\(\s*\).*\zs{\s*$/\r\1{/
Breakdown:
^\(\s*\) = capture the whitespace at the beginning of the line
.* = everything else
\zs = start replacement after this
{ = open curly brace
\s*$ = trailing whitespace before line end
\r\1{ = newline, captured whitespace, brace
I don't know if this completely solves your problem, but if this is a one-shot operation, you might want to try regular expressions:
:%s/^\(\s*\)\(.*)\)\s*{\s*$/\1\2^M\1{/
Note that ^M is a control character that is usually generated (depending on your terminal) by pressing CTRL-V followed by ENTER.
EDIT: As pointed out in the comments by Jay and Zyx, \r is a better way of inserting a line break into the replaced string. I wasn't aware of that, many thanks for the hint.
If you install Artistic Style you can do something like:
:set formatprg=astyle\ -b
Then use gq to reformat chunks of code.emphasized text
If you want this enabled every time you edit a C file,
you can add the following to your .vimrc file.
autocmd BufNewFile,BufRead *.c set formatprg=astyle\ -b
I don't know if you can do it within vim itself, but you can try the BSD indent command with the -bl option. With the cursor on the first {, you can type !%indent -blEnter.