Unwanted question marks in noweb output - noweb

I have the following noweb file, titled test
\documentclass{article}
\usepackage{noweb}
\begin{document}
\section{Hello World}
This is a program
<<example.py>>=
print("Hello, world!")
#
\end{document}
I type the following commands:
pdflatex test.tex
evince test.pdf
The pdf looks something like this:
?? <example.py ??>=
print("Hello, world!")
This code is written to file example.py
What are these question marks and how do I get rid of them?

You have to run pdflatex test.tex a second time. The first run generates warnings about undefined cross-references. Those cross-references are defined in the generated aux file, which is then used with the second pass.

Related

How to write a string in a file using vim editor from command line

I want to create a new file using vi editor from command line and add a string to it multiple times say 100. Using vi -S command.script file.txt is supposed to do the trick where a new file file.txt will be created and the commands given in command.script file can write to this file. My command.script contains
:%100a hello world
:wq
But its's not working, what I am doing wrong?
If you interactively execute :%100a hello world in a Vim session, you'll get E488: Trailing characters. Looking up :help :a:
:{range}a[ppend][!] Insert several lines of text below the specified
line. If the {range} is missing, the text will be
inserted after the current line. [...]
These two commands will keep on asking for lines, until you type a line
containing only a ".".
tells you that the text has to be put in following lines (and concluded by a line with only a . character).
Or did you mean to use the normal mode a command? (That one takes a [count] to multiply; your %100 range is wrong, too!)
You can also use the low-level function append(), repeating the string with repeat().
summary
$append
hello world
[...]
hello world
.
execute "$normal! 100ahello world\<CR>"
" Easier with o instead of a:
$normal! 100ohello world
call append('$', repeat(['hello world'], 100))
non-Vim alternatives
But honestly, if that is your real use case (and not just a simplified toy example), you don't need Vim at all for this. Here's one example for the Bash shell:
$ for i in $(seq 100); do echo "hello world" >> file.txt; done

Printing the word echo in the output of cat file

I am trying to generate a file using cat in bash where inside the bash, i already ran a script, that i saved into a variable then will be used inside the cat. To ran the script and save the output to a variable, I used the following:
declare RESULT=$(./script.pl 5 5 5)
Next, I show an excerpt of the cat file where the variable RESULT is being used.
cat> input.in<<EOF
bla bla
echo $RESULT
EOF
What I obtain after running the bash, is the correct output of the variable RESULT. However, there is a word echo in the beginning of the file (as shown below). This is problematic because I am trying to automate a code, and adding the word echo ruins the code.
echo K_POINTS crystal
64
0.00000000 0.00000000 0.00000000 1.562500e-02
0.00000000 0.00000000 0.25000000 1.562500e-02
0.00000000 0.00000000 0.50000000 1.562500e-02
Can you tell me please what is the problem? Thanks a lot!
Here documents don't run the contents as commands, they just expand values like $RESULT.
cat> input.in<<EOF
bla bla
$RESULT
EOF
If you wanted to actually get the output of a command, you can use $(mycommand myarg) but obviously this is pointless for echo
Maybe I'm not reading this correctly (apologies if so), but it looks like you are expecting the heredoc to be run as a script. It is not. It is just created and cat'ed to input.in, and the string 'echo' is included in that output.
Try removing the string 'echo' from the heredoc (I assume that your perl output starts with the token K_POINTS).
i.e.:
declare RESULT=$(./script.pl 5 5 5)
cat> input.in<<EOF
bla bla
$RESULT
EOF

String concatenation in bash 3.2.57 (macOS)

My goal is to concatenate two strings.
Here's a copy-paste of my bash script:
str1="Hello"
str2="World"
str3=$str1$str2
echo $str3
The expected output is HelloWorld but I'm getting World instead.
It works fine when I run it in the terminal.
Here's the output when I run cat -v on my script:
str1="Hello"^M
str2="World"^M
str3=$str1$str2^M
echo $str3^M
Am I missing something?
That's probably because you have a carriage return (\r) at the end of $str1. I'm getting the same output with the following:
#!/bin/bash
str1="Hello"$'\r'
str2="World"
str3=$str1$str2
echo $str3
It often happens when you create the script on a MSWin machine.
It prints Hello, but then \r moves the cursor back to the beginning of the line, and overwrites the Hello with World.
You can verify it by running it through a hex dump or cat -v.

When echo text in .tcsh file the less command is not working properly

I have a strange problem that I didn't able to find solution for it:
When I login to my environment it configured to work with tcsh (I want to keep it like that), but when I edit the file ".tcshrc" and put the below code (Only these 2 lines), the text is printed correctly in RED, but after that the "less" command is not working anymore.
When I remove this line, less command works properly.
#!/bin/tcsh
echo "THIS LINE IS OK"
Does someone knows what could be the reason? I'm using less version: (less 436)
I create a text file: "dummy.txt" and write the following text inside: "THIS IS A DUMMY FILE"
CMD: cat dummy.txt
OUTPUT:
THIS IS A DUMMY FILE
CMD: less dummy.txt
OUTPUT:
THIS LINE IS OK
dummy.txt (END)
Only less command is not working, other commands: cat, more, vi are working properly.
Thanks in advance to the once who try to assist.
Ok, I found the issue, it is well explained in the following link:
http://www.greenwoodsoftware.com/less/faq.html#profileout
I have moved my code to ".login" instead.

SCons removes space from Action/Command

With the following command:
env.Command('XYZ', 'somefile', 'echo "Hello, how are you" > $TARGET')
SCons squashes the space and runs:
echo "Hello, how are you" > XYZ
And:
$ cat XYZ
Hello, how are you
Why is this and can I stop it?
This is a known problem, documented in the bugs #1123 and #2018.
In your case where you simply want to create a text file, there is a simple workaround which has the additional benefit of working cross-platform: using the Textfile Builder...
env = Environment(tools=['default', 'textfile'])
env.Textfile('XYZ','Hello, how are you')
This will create the target file with a *.txt extension, because that's the default of the Builder. If you don't like it, you can overwrite the variable $TEXTFILESUFFIX. Either globally in the Environment, or locally for a single Builder call like:
env.Textfile('XYZ','Hello, how are you', TEXTFILESUFFIX='')

Resources