How to use tikz in manim? - tikz

I am trying to use tikz in manim. The version of manim I used is 3feb2019. I have added necessary packages into tex_template file. But it throws an error:
IndexError: list index out of range
I have no idea to solve this bug. Could anyone help me?
EDIT: Here are the codes I tried to render.
# These are in the example_scenes.py file
class TikzMobject(TextMobject):
CONFIG = {
"stroke_width":3,
"fill_opacity":0,
"stroke_opacity":1
}
class TikzExample3(Scene):
def construct(self):
example_tex = TikzMobject(
r"""
\begin{tikzpicture}
\draw (-1,0)--(1,0);
\end{tikzpicture}
"""
)
self.play(Write(example_tex))
self.wait()
I have tried both latest version of manim and the 3feb version but it just threw the same error:list index out of range. And I can compile the tikz codes in the output tex file. The platform I used is Windows.

I have already tried it on 2 Windows and it works perfectly, it is likely that you have not configured your tex_template.tex correctly, or that you are using an old version of Python (at least Python 3.7.3 is required), here are the proof that it works for me.
tex_template.tex configuration:
\documentclass[preview]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{dsfont}
\usepackage{setspace}
\usepackage{tipa}
\usepackage{relsize}
\usepackage{textcomp}
\usepackage{mathrsfs}
\usepackage{calligra}
\usepackage{wasysym}
\usepackage{ragged2e}
\usepackage{physics}
\usepackage{xcolor}
\usepackage{microtype}
\usepackage{tikz} %<------------------------- TIKZ PACKAGE
\DisableLigatures{encoding = *, family = * }
%\usepackage[UTF8]{ctex}
\linespread{1}
\begin{document}
YourTextHere
\end{document}
OUTPUT

Related

MATLAB — Unable to Import cv2 Library

I'm a beginner at OpenCV, and trying to run an open-source program.
http://asrl.utias.utoronto.ca/code/gpusurf/index.html
I currently have the Computer Vision Toolbox OpenCV Interface 20.1.0 installed and Computer Vision Toolbox 9.2.
I cannot run this simple open-source feature matching algorithm without encountering errors.
import cv2
import matplotlib.pyplot as plt
%matplotlib inline
% read images
img1 = cv2.imread('[INSERT PATH #1]');
img2 = cv2.imread('[INSERT PATH #2]');
img1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY);
img2 = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY);
%sift
sift = cv2.xfeatures2d.SIFT_create();
keypoints_1, descriptors_1 = sift.detectAndCompute(img1,None);
keypoints_2, descriptors_2 = sift.detectAndCompute(img2,None);
len(keypoints_1), len(keypoints_2)
The following message is returned:
Error: File: Keypoints.m Line: 1 Column: 8
The import statement 'import cv2' cannot be found or cannot be imported. Imported names must end with '.*' or be
fully qualified.
However, when I remove Line 1, I instead get the following error.
Error: File: Keypoints.m Line: 2 Column: 8
The import statement 'import matplotlib.pyplot' cannot be found or cannot be imported. Imported names must end
with '.*' or be fully qualified.
Finally, following the error message only results in a sequence of further errors from the cv2 library. Any ideas?
That's because the code you've used isn't MATLAB code, it's python code.
As per the website you've linked:
From within Matlab
The parallel implementation coded in Matlab can be run by using the surf_find_keypoints() function. The output keypoints can be sorted by strength using surf_best_n_keypoints(), and plotted using surf_plot_keypoints().
Check that you've downloaded the correct files and try again.
Furthermore, the Matlab OpenCV Interface is designed to integrate C++ OpenCV code, not python. Documentations here.
Yes, it is correct that this is Python code. I would recommend checking your dependencies/libraries. The PyCharm IDE is what I personally use since it takes care of all the libraries easily.
If you do end up trying out PyCharm click on the red icon when hovering on CV2. It’ll then give you a prompt to download the library.
Edit:
Using Python some setup can be done. Using pip:
Install opencv-python
pip install opencv-python
Install opencv-contrib-python
pip install opencv-contrib-python
Unfortunately, there is some issue with the sift feature since by default it is excluded from newer free versions of OpenCV.
sift = cv2.xfeatures2d.SIFT_create() not working even though have contrib installed
import cv2
Image_1 = cv2.imread("Image_1.png", cv2.IMREAD_COLOR)
Image_2 = cv2.imread("Image_2.jpg", cv2.IMREAD_COLOR)
Image_1 = cv2.cvtColor(Image_1, cv2.COLOR_BGR2GRAY)
Image_2 = cv2.cvtColor(Image_2, cv2.COLOR_BGR2GRAY)
sift = cv2.SIFT_create()
keypoints_1, descriptors_1 = sift.detectAndCompute(Image_1,None)
keypoints_2, descriptors_2 = sift.detectAndCompute(Image_2,None)
len(keypoints_1), len(keypoints_2)
The error I received:
"/Users/michael/Documents/PYTHON/Test Folder/venv/bin/python" "/Users/michael/Documents/PYTHON/Test Folder/Testing.py"
Traceback (most recent call last):
File "/Users/michael/Documents/PYTHON/Test Folder/Testing.py", line 9, in <module>
sift = cv2.SIFT_create()
AttributeError: module 'cv2.cv2' has no attribute 'SIFT_create'
Process finished with exit code 1

jupyter notebook with unicode characters PDF converting problems

I was making a math class note with some unicode characters (Simplified Chinese, in my case) in it. And when I was trying to convert it into PDF file, it popped out 500 error. The error message reads:
...
*************************************************
("E:\Program Files (x86)\MiKTeX 2.9\tex\latex\fontspec\fontspec.sty"
("E:\Program Files (x86)\MiKTeX 2.9\tex\latex\fontspec\fontspec-xetex.sty"
("E:\Program Files (x86)\MiKTeX 2.9\tex\latex\base\fontenc.sty"
("E:\Program Files (x86)\MiKTeX 2.9\tex\latex\base\tuenc.def"))
("E:\Program Files (x86)\MiKTeX 2.9\tex\latex\fontspec\fontspec.cfg")
! Undefined control sequence.
<argument> \LaTeX3 error:
Erroneous variable \c__fontspec_shape_n_n_tl used!
l.3806 \emfontdeclare{ \emshape, \eminnershape }
?
! Emergency stop.
<argument> \LaTeX3 error:
Erroneous variable \c__fontspec_shape_n_n_tl used!
l.3806 \emfontdeclare{ \emshape, \eminnershape }
No pages of output.
Transcript written on notebook.log.
I guess the fontspec part went wrong, but I don't know how to solve it.
For your information, here is what I've done before I got the 500 error.
1.I've installed the pandoc, and I already have Miktex before;
2.I've changed the file
...\nbconvert\templates\latex\article.tplx
rewritten the article class to be ctexart;
3.I've changed the file
...\nbconvert\templates\latex\exporters\pdf.py
rewritten the latex command to be
latex_command = List([u"xelatex", u"{filename}"], config=True,
help="Shell command used to compile latex."
)
4.I've also tried this:"https://github.com/ipython/ipython/issues/7150", which tends to convert the ipynb file into latex file first, then into PDF. And this didn't work for me either. The main reason is that the config file can't be found by jupyter nbconvert command.
For your information, my OS is Win7 Ultimate x64, with Chrome for Anaconda3 jupyter notebook.
Thanks in advance for anyone who takes time to read my post. Any help would be appreciated.

Packaging MongoDB with packager.py

Trying to package my custom built MongoDB 2.6.6 (with SSL), I'm using the packager.py script from buildscript/ in the sources I got from www.mongodb.org.
I've changed it in a few places, based on this and on errors I've had because of file locations.
I've come along way, but now the error I'm getting is from within rpmbuild:
error: File not found: /tmp/tmp7vZvNP/rpmbuild/BUILDROOT/mongodb-org-2.6.6-1.%{_arch}/usr/bin/mongod
Put aside the fact I searched and couldn't find where the %{_arch} thing came from, the mongod binary file exists in /tmp/tmp7vZvNP/rpmbuild/BUILDROOT/mongodb-org-2.6.6-1.%\{_arch\}/usr/bin/mongodb-linux-x86_64-2.6.6/bin/
Where is {_bindir} defined for the spec file?
Any other idea what's the next thing I should be pursuing?
So after reading #Etan Reisner's comment, I did the following:
Changed write_rpm_macros_file to look like this:
def write_rpm_macros_file(path, topdir, arch):
f=open(path, 'w')
try:
f.write("%%_topdir %s\n" % topdir)
f.write("%%_arch %s\n" % arch)
f.write("%%_bindir %s" % "/usr/bin/mongodb-linux-x86_64-2.6.6/bin/")
finally:
f.close()
And now I have an RPM built correctly.
Edit:
I changed the binaries tar.gz file and now the %_bindir macro is not needed...

Pyinstaller --onefile warning pyconfig.h when importing scipy or scipy.signal

This is very simple to recreate.
If my script foo.py is:
import scipy
Then run:
python pyinstaller.py --onefile foo.py
When I launch foo.exe I get:
WARNING: file already exists but should not: C:\Users\username\AppData\Local\Temp\_MEI86402\Include\pyconfig.h
I've tested a few versions but the latest I've confirmed is 2.1dev-e958e02 running on Win7, Python 2.7.5 (32 bit), Scipy version 0.12.0
I've submitted a ticket with the Pyinstaller folks but haven't heard anything yet. Any clues how to debug this further?
You can hack the spec file to remove the second instance by adding these lines after a=Analysis:
for d in a.datas:
if 'pyconfig' in d[0]:
a.datas.remove(d)
break
The answer by wtobia# worked for me. See https://github.com/pyinstaller/pyinstaller/issues/783
Go to C:\Python27\Lib\site-packages\PyInstaller\build.py
Find the def append(self, tpl): function.
Change if tpl[2] == "BINARY": to if tpl[2] in ["BINARY", "DATA"]:
Expanding upon Ilya's solution, I think this is a little bit more robust solution to modifying the spec file (again place after the a=Analysis... statement).
a.datas = list({tuple(map(str.upper, t)) for t in a.datas})
I only tested this on a small test program (one with a single import and print statement), but it seems to work. a.datas is a list of tuples of strings which contain the pyconfig.h paths. I convert them all to lowercase and then dedup. I actually found that converting all of them all to lowercase was sufficient to get it to work, which suggests to me that pyinstaller does case-sensitive deduping when it should be case-insensitive on Windows. However, I did the deduping myself for good measure.
I realized that the problem is that Windows is case-insensitive and these 2 statements are source directories are "duplicates:
include\pyconfig.h
Include\pyconfig.h
My solution is to manually tweak the .spec file with after the a=Analysis() call:
import platform
if platform.system().find("Windows")>= 0:
a.datas = [i for i in a.datas if i[0].find('Include') < 0]
This worked in my 2 tests.
A more flexible solution would be to check ALL items for case-insensitive collisions.
I ran the archive_viewer.py utility (from PyInstaller) on one of my own --onefile executables that has the same error and found that pyconfig.h is included twice:
(31374007, 6521, 21529, 1, 'x', 'include\\pyconfig.h'),
(31380528, 6521, 21529, 1, 'x', 'Include\\pyconfig.h'),
(31387049, 984, 2102, 1, 'x', 'pytz\\zoneinfo\\CET'),
Sadly though, I don't know how to fix it.
PyInstaller Manual link:
http://www.pyinstaller.org/export/d3398dd79b68901ae1edd761f3fe0f4ff19cfb1a/project/doc/Manual.html#archiveviewer

Multiple figures in one chunk with knitr and Rstudio 0.97 or 0.98

I try to shift from Sweave to knitr but I am stucked with a problem to use multiple plots in one chunk. Here an example:
Let this .Rnw simple file (named Essai.Rnw). Of course only one plot is shown in the pdf:
\documentclass{article}
\begin{document}
\SweaveOpts{concordance=TRUE}
<<fig=TRUE>>=
plot(1:10, exp(1:10))
plot(1:10, log(1:10))
#
\end{document}
I transform it to knitr format using:
library("knitr", lib.loc="/Library/Frameworks/R.framework/Versions/3.0/Resources/library")
Sweave2knitr("Essai.Rnw")
I edit the file to get this:
\documentclass{article}
\begin{document}
\SweaveOpts{concordance=TRUE}
<<include=FALSE>>=
require(knitr)
opts_chunk$set(concordance=TRUE)
#
<<>>=
plot(1:10, exp(1:10))
plot(1:10, log(1:10))
#
\end{document}
In Rstudio global preference, I set Weave Rnw files using Knitr and when I produce pdf file using Compile pdf button in Rstudio, i get only one plot, not the 2 as I expected.
Here is my sessionInfo()
> sessionInfo()
R version 3.0.1 Patched (2013-06-10 r62935)
Platform: x86_64-apple-darwin10.8.0 (64-bit)
locale:
[1] fr_FR.UTF-8/fr_FR.UTF-8/fr_FR.UTF-8/C/fr_FR.UTF-8/fr_FR.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] knitr_1.2
loaded via a namespace (and not attached):
[1] digest_0.6.3 evaluate_0.4.3 formatR_0.7 stringr_0.6.2 tools_3.0.1
Not sure this is the cause of your problem but if you weave it with knitr, I think you have to remove the \SweaveOpts{concordance=TRUE} line.
If I compile the following, I get two plots. Note the deletions I made. Your original code did not compile on my system.
\documentclass{article}
\begin{document}
<<include=FALSE>>=
opts_chunk$set(concordance=TRUE)
#
<<>>=
plot(1:10, exp(1:10))
plot(1:10, log(1:10))
#
\end{document}
Maybe read about the knitr option fig.keep= about how your plots get integrated into the output.