pandoc error: divide by zero - python-sphinx

I am writing a book. The orginal format is reST, and sphinx is used to generate HTML/epub format. However it has to be converted into docx, since the editor think it is a good raw format for Indesign in their daily process.
A shell script is used:
#!/bin/bash
cd ./source
echo foreword
pandoc -o foreword.docx foreword.rst
echo ch001
pandoc -o ch001.docx ch001.rst
echo ch002
pandoc -o ch002.docx ch002.rst
echo ch002b
pandoc -o ch002b.docx ch002b.rst
echo ch003
pandoc -o ch003.docx ch003.rst
echo ch004
pandoc -o ch004.docx ch004.rst
echo ch005
pandoc -o ch005.docx ch005.rst
echo ch006
pandoc -o ch006.docx ch006.rst
echo ch007
pandoc -o ch007.docx ch007.rst
echo ch008
pandoc -o ch008.docx ch008.rst
echo ch009
pandoc -o ch009.docx ch009.rst
echo futureplan
pandoc -o futureplan.docx futureplan.rst
mv *.docx ../release/
cd ../
I got the following result from console:
foreword
ch001
ch002
ch002b
ch003
pandoc: divide by zero
ch004
ch005
pandoc: divide by zero
ch006
pandoc: divide by zero
ch007
pandoc: divide by zero
ch008
pandoc: divide by zero
ch009
pandoc: divide by zero
futureplan
Any document which was complainted for divide by zero has only 30B in file size.
Please tell me know to locate and fix that error. I can not find any clue from documentation and group.
Maybe it is a bug, but I have to avoid this issue since the scheduler is very tight.

Finally, I downloaded latest version pandoc for Windows.
Since rest to docx will drop some pictures, I use another work around method.
reST to HTML by sphinx, HTML to docx by pandoc.

Related

Makefile provides blank tex files

I am currently in the process of writing quite a large document, that I divided into multiple chapters. What I chose to do is to put each chapter in a different file, and then compile them with a makefile into one big document. When I type make get in the terminal, the .tex docs appear with the right name in my folder but completely blank.
Here is my makefile :
pdf:
pdflatex --shell-escape file.tex
clean:
rm -f chapter1.tex
rm -f chapter2.tex
get:
sed -e '/BEGIN_BOOK/,/END_BOOK/!d' ../01-chapter1/chapter1.tex> chapter1.tex
sed -e '/BEGIN_BOOK/,/END_BOOK/!d' ../02-chapter2/chapter2.tex> chapter2.tex
diff:
git latexdiff HEAD -- --main file.tex --latexopt "--shell-escape"
But if I replace these blank ones with the correct files, the make command works properly and I get what I want.
Thank you in advance

Can Pandoc output syntax-highlighted codeblocks from a vimwiki source?

For markdown Pandoc's syntax highlighting works great, for example for a file
test.md that looks like this
some text...
```sh
for i in {1,2,3}; do echo ${i}; done
```
the command
pandoc -f markdown -t html -s --highlight-style=zenburn -o out.html test.md
generates html-output out.html that basically has the syntax highlighting
specified in zenburn "baked in" and a browser renders it as you'd want:
However for the vimwiki-format (which pandoc supports) this doesn't seem to
work even though I haven't found anything saying the syntax highlighting was
limited only to some source formats.
Basically: Can I get pandoc to do the same style of syntax highlighting in the
html output if my source format is vimwiki and my source looks like this:
some text...
{{{sh
for i in {1,2,3}; do echo ${i}; done
}}}
because doing
pandoc -f vimwiki -t html -s --highlight-style=zenburn -o out.html test.wiki
yields (what you can also tell from the generated html) this:

In Bash, how can I use process substitution to create a template for Pandoc?

I'm trying to modify the default Pandoc LaTeX template (a small setting concerning tables) and I'm trying to do this and the Pandoc run all in one command. I'm getting the error pandoc: Could not find data file /dev/fd/63.latex when I try to execute the command and I'm not sure how to address it. The command is as follows:
pandoc --template <(pandoc --print-default-template=latex | sed 's/longtable,//') -f markdown -t latex report.md -o report.pdf
How should I be doing this process substitution?

Bash: replace part of filename

I have a command I want to run on all of the files of a folder, and the command's syntax looks like this:
tophat -o <output_file> <input_file>
What I would like to do is a script that loops over all the files in an arbitrary folder and also uses the input file names to create similar, but different, output file names. The file names looks like this:
input name desired output name
path/to/sample1.fastq path/to/sample1.bam
path/to/sample2.fastq path/to/sample2.bam
Getting the input to work seems simple enough:
for f in *.fastq
do
tophat -o <output_file> $f
done
I tried using output=${f,.fastq,.bam} and using that as the output parameter, but that doesn't work. All I get is an error: line 3: ${f,.fastq,.bam}: bad substitution. Is this the way to do what I want, or should I do something else? If it's the correct way, what am I doing wrong?
[EDIT]:
Thanks for all the answers! A bonus question, though... What if I have files named like this, instead:
path/to/sample1_1.fastq
path/to/sample1_2.fastq
path/to/sample2_1.fastq
path/to/sample2_2.fastq
...
... where I can have an arbitrary number of samples (sampleX), but all of them have two files associated with them (_1 and _2). The command now looks like this:
tophat -o <output_file> <input_1> <input_2>
So, there's still just the one output, for which I could do something like "${f/_[1-2].fastq/.bam}", but I'm unsure how to get a loop that only iterates once over every sampleX at the same time as taking both the associated files... Ideas?
[EDIT #2]:
So, this is the final script that did the trick!
for f in *_1.fastq
do
tophat -o "${f/_1.fastq/.bam}" $f "${f/_1.fastq/_2.fasq}"
done
You can use:
tophat -o "${f/.fastq/.bam}" "$f"
Testing:
f='path/to/sample1.fastq'
echo "${f/.fastq/.bam}"
path/to/sample1.bam
Not an answer but a suggestion: as a bioinformatician, you shoud use GNU make and its option -j (number of parallel jobs). The Makefile would be:
.PHONY:all
FASTQS=$(shell ls *.fastq)
%.bam: %.fastq
tophat -o $# $<
all: $(FASTQS:.bam=.fastq)
Alternative to anubhava's concise solution,
d=$(dirname path/to/sample1.fastq)
b=$(basename path/to/sample1.fastq .fastq)
echo $d/$b.fastq
path/to/sample1.fastq
tophat -o "$d/$b.fastq" "$f"

How can I accomplish this `cat` usage more tersely?

Open ended question (be creative!) for a real use case. Essentially I want to cat (1) an existing file (2) the output of a program and (3) a specific bit of text. Between pipes, echo and redirects, I feel like I should be able to do better than this!
pandoc -t latex -o mydoc.tex mydoc.rst
echo \\end{document} > footer.tex
cat header.tex mydoc.tex footer.tex > fulldoc.tex
{
cat header.tex
pandoc -t latex mydoc.rst
echo \\end{document}
} > fulldoc.tex
If you're using bash, you can use process substitution and a here string:
cat header.tex <(pandoc -t latex mydoc.rst) <<<'\end{document}' > fulldoc.tex

Resources