gnuplot with texshop in osx - latex

I have installed gnuplot through macports but when i compile my latex document in texshop it doesn't show the plots and I get these errors in the log file:
Package pgf Warning: Plot data file `tutorial.x.table' not found. on input line
17.
Package pgf Warning: Plot data file `tutorial.sin.table' not found. on input li
ne 19.
Package pgf Warning: Plot data file `tutorial.exp.table' not found. on input li
ne 21.
I'm just trying to compile this basic example:
% Author: Till Tantau
% Source: The PGF/TikZ manual
\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
% GNUPLOT required
\begin{document}
\pagestyle{empty}
\begin{tikzpicture}[domain=0:4]
\draw[very thin,color=gray] (-0.1,-1.1) grid (3.9,3.9);
\draw[->] (-0.2,0) -- (4.2,0) node[right] {$x$};
\draw[->] (0,-1.2) -- (0,4.2) node[above] {$f(x)$};
\draw[color=red] plot[id=x] function{x}
node[right] {$f(x) =x$};
\draw[color=blue] plot[id=sin] function{sin(x)}
node[right] {$f(x) = \sin x$};
\draw[color=orange] plot[id=exp] function{0.05*exp(x)}
node[right] {$f(x) = \frac{1}{20} \mathrm e^x$};
\end{tikzpicture}
\end{document}

Yes, you need to turn the .gnuplot files that tikz creates into the tables files. You have two choices for this:
you can run (pdf)latex with the additional command line switch --shell-escape, sometimes also called --enable-write-18, then gnuplot is run automatically for you. (You might not be comfortable with allowing arbitrary programs to be starte from within pdflatex, though.)
you can run gnuplot yourself on the test.exp.gnuplot, test.sin.gnuplot, test.x.gnuplot etc. files. Simply gnuplot test.exp.gnuplot should do it. (Can't verify here, since my gnuplot version is too old.)

Related

pgfplots not working with TexLive on Windows

\begin{tikzpicture}
\begin{axis}
\addplot[color=red]{exp(x)};
\end{axis}
\end{tikzpicture}
%Here ends the 2D plot
\hskip 5pt
%Here begins the 3D plot
\begin{tikzpicture}
\begin{axis}
\addplot3[
surf,
]
{exp(-x^2-y^2)*x};
\end{axis}
\end{tikzpicture}
Gives the following error:
Package tikz: Sorry, the system call 'pdflatex -halt-on-error -interaction=batchmode -jobname "main-figure0" "\def\tikzexternalrealjob{main}\input{main}"' did NOT result in a usable output file 'main-figure0' (expected one of .pdf:.jpg:.jpeg:.png:). Please verify that you have enabled system calls. For pdflatex, this is 'pdflatex -shell-escape'. Sometimes it is also named 'write 18' or something like that. Or maybe the command simply failed? Error messages can be found in 'main-figure0.log'. If you continue now, I'll try to typeset the picture.
And when looking in the log:
This is pdfTeX, Version 3.141592653-2.6-1.40.24 (TeX Live 2022) (preloaded format=pdflatex 2022.4.7) 8 FEB 2023 12:32
entering extended mode
restricted \write18 enabled.
file:line:error style messages enabled.
%&-line parsing enabled.
**PATH/main.tex
(PATH/main.tex
LaTeX2e <2021-11-15> patch level 1
L3 programming layer <2022-02-24> (c:/texlive/2022/texmf-dist/tex/latex/base/report.cls
Document Class: report 2021/10/04 v1.4n Standard LaTeX document class
(c:/texlive/2022/texmf-dist/tex/latex/base/size11.clo
File: size11.clo 2021/10/04 v1.4n Standard LaTeX file (size option)
)
(when compiling with --escape-shell):
This is pdfTeX, Version 3.141592653-2.6-1.40.24 (TeX Live 2022) (preloaded format=pdflatex 2022.4.7) 8 FEB 2023 13:22
entering extended mode
\write18 enabled.
%&-line parsing enabled.
**main.tex
(./main.tex
LaTeX2e <2021-11-15> patch level 1
L3 programming layer <2022-02-24>
(c:/texlive/2022/texmf-dist/tex/latex/base/report.cls
Document Class: report 2021/10/04 v1.4n Standard LaTeX document class
(c:/texlive/2022/texmf-dist/tex/latex/base/size11.clo
File: size11.clo 2021/10/04 v1.4n Standard LaTeX file (size option)
)
and later:
===== 'mode=convert with system call': Invoking 'pdflatex -halt-on-error -interaction=batchmode -jobname "main-figure0" "\def\tikzexternalrealjob{main}\input{main}"' ========
runsystem(pdflatex -halt-on-error -interaction=batchmode -jobname "main-figure0" "\def\tikzexternalrealjob{main}\input{main}")...disabled (restricted).
\openout3 = `main.auxlock'.
./0_abstract.tex:14: Package tikz Error: Sorry, the system call 'pdflatex -halt-on-error -interaction=batchmode -jobname "main-figure0" "\def\tikzexternalrealjob{main}\input{main}"' did NOT result in a usable output file 'main-figure0' (expected one of .pdf:.jpg:.jpeg:.png:). Please verify that you have enabled system calls. For pdflatex, this is 'pdflatex -shell-escape'. Sometimes it is also named 'write 18' or something like that. Or maybe the command simply failed? Error messages can be found in 'main-figure0.log'. If you continue now, I'll try to typeset the picture.
See the tikz package documentation for explanation.
Type H <return> for immediate help.
...
l.14 \end{tikzpicture}
I have included the right packages etc.:
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{width=10cm,compat=1.9}
% We will externalize the figures
\usepgfplotslibrary{external}
\tikzexternalize
I have also tried running it with things such as:
--shell-escape main.tex
--enable-write18 main.tex
or adding
\tikzexternalize[shell escape=-shell-escape]
But this does not seem to work, everything does work correctly when I e.g. open it in Overleaf.
minimal reproducible example:
\documentclass[11pt,a4paper,oneside]{report}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{width=10cm,compat=1.9}
% We will externalize the figures
\usepgfplotslibrary{external}
\tikzexternalize
% Do not automatically indent text
\setlength\parindent{0pt}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot[color=red]{exp(x)};
\end{axis}
\end{tikzpicture}
%Here ends the 2D plot
\hskip 5pt
%Here begins the 3D plot
\begin{tikzpicture}
\begin{axis}
\addplot3[
surf,
]
{exp(-x^2-y^2)*x};
\end{axis}
\end{tikzpicture}
\end{document}

Create multiple pdf files from same tex file

I have multiple data files (result_a.csv, result_b.csv, ..) and I want to create plot for each one (result_a.pdf, result_b.pdf - or similar). The plot is the same but the input file is different and the output file is different. Is there a way I can run a loop, pass the parameter names from the outside and save the output with a distinctive name?
Assume that my code for creating the plot -
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{ytick style={draw=none}, xtick style={draw=none}}
\usetikzlibrary{patterns}
\newcommand\param{a}
\begin{document}
\begin{tikzpicture}
\footnotesize
\begin{semilogxaxis}
\addplot[color=red,mark=triangle] table [x=x,y=y,col sep=comma, mark=*] {result_\param.csv};
\end{semilogxaxis}
\end{tikzpicture}
\end{document}
Assuming your file is called document.tex, you can pass the name of the csv file to the document by compiling with the following command
pdflatex -jobname="document-b" "\\newcommand*\\version{b}\\input{document}"
and the document:
\documentclass[tikz]{standalone}
% setting a default value in case it is compiled without the newcommand
\unless\ifdefined\version
\def\version{a}
\fi
\usepackage{pgfplots}
\pgfplotsset{ytick style={draw=none}, xtick style={draw=none}}
\usetikzlibrary{patterns}
\newcommand\param{a}
\begin{document}
\begin{tikzpicture}
\footnotesize
\begin{semilogxaxis}
\addplot[color=red,mark=triangle] table [x=x,y=y,col sep=comma, mark=*] {result_\version.csv};
\end{semilogxaxis}
\end{tikzpicture}
\end{document}
If you are working under a Linux Distro or under a Mac OS, you may use a shell script.
Let init.tex be the tex file with
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{ytick style={draw=none}, xtick style={draw=none}}
\usetikzlibrary{patterns}
\newcommand\param{a}
\begin{document}
\begin{tikzpicture}
\footnotesize
\begin{semilogxaxis}
\addplot[color=red,mark=triangle] table [x=x,y=y,col sep=comma, mark=*] {
and let ends.tex be the file containing
};
\end{semilogxaxis}
\end{tikzpicture}
The following script reads each .csv file, puts its contents in a tex file organized as follows:
init.tex
result_x.csv
ends.tex
produces the tex file result_xx.tex and compiles it, providing the file result_xx.pdf
#!/bin/bash
for i in $(ls *.csv)
do
a=$(basename -s .csv $i)
cp init.tex $a.tex
echo $i >> $a.tex
cat ends.tex >> $a.tex
pdflatex $a.tex
done
It is a naive solution, there are more experienced than me bash--script writers here in SO, but it should work.
PS. Remember to make the script executable to make it work:
chmod 755 myscript.sh
See for example here.

"Error Producing PDF" when markdown contains a horizontal rule: --- or ***

When my Markdown file contains a horizontal rule --- or *** I receive an error regarding \Linethickness -> \Protect
I understand there have been issues with MiKTeX recently, however I am unsure whether they apply here.
I have been experiencing this issue since yesterday morning, when I was playing around trying to get the Lato font package to work with a set of Markdown files I need to convert to PDF. It had been working fine (asides from the font issue).
This could have happened when I updated MiKTeX, although at the time I hadn't realised that could be the case, as I was also playing with the templates, YAML, PS Script etc.
Since then I've been reading about the MiKTeX issue and I've tried further updates, updating package database, building formats, refreshing file name database and uninstalling and reinstalling. I have read the background in the comments section on GitHub but the suggestions there do not seem to have solved it for me, whereas they have for others.
This makes me question whether this is related, but I am relatively new to Tex, Markdown etc.
The original file was longer and more complex, but this Markdown
# Sample File
Test Test Test
---
Produces the same error
Error producing PDF.
! Missing number, treated as zero.
<to be read again>
\protect
\linethickness ->\protect
\linethickness
\setlength #1#2->#1 #2
\relax
\#rule ...#tempdimb {#2}\setlength \#tempdimc {#3}
\advance \#tempdimc \#temp...
l.362 ...nter}\rule{0.5\linewidth}{\linethickness}
Removing the --- allows the pdf to generate in both the above example and my more complex markdown file, even with templates.
I am unsure if linethickness is within the graphics package, when I look at package information I can't see anything that obviously indicates it is.
I would simply remove the offending lines but they are used throughout the remainder of the markdown files and I would prefer to find a fix, with your help, if possible!
Please could you let me know if I'm barking up the wrong tree with this recent MiKTeX issue or not, and if not, where I might be going wrong.
Many Thanks in advance.
Update:
I ran this command
pandoc -s sample.md -o sample.tex
to produce this tex:
% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[
]{article}
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
\usepackage{unicode-math}
\defaultfontfeatures{Scale=MatchLowercase}
\defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
\usepackage[]{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\#ifundefined{KOMAClassName}{% if non-KOMA class
\IfFileExists{parskip.sty}{%
\usepackage{parskip}
}{% else
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
\KOMAoptions{parskip=half}}
\makeatother
\usepackage{xcolor}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\hypersetup{
hidelinks,
pdfcreator={LaTeX via pandoc}}
\urlstyle{same} % disable monospaced font for URLs
\usepackage[margin=1cm]{geometry}
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{-\maxdimen} % remove section numbering
\date{}
\begin{document}
\setcounter{errorcontextlines}{40}
\hypertarget{sample-file}{%
\section{Sample File}\label{sample-file}}
Test Test Test
\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
\end{document}
meanwhile, I tried this (as root in a latest RStudio Debian install):
~# sed 's,\\linethickness,0.5000000000pt,g' < pandoc/pandoc > /usr/lib/rstudio-server/bin/pandoc/pandoc
where the 1st pandoc/pandoc is a copy of the original from package. That keeps the same string length and valid number so that the binary won't break. That writes the hrule as:
\begin{center}\rule{0.5\linewidth}{0.5000000000pt}\end{center}
and MiKTeX seems fine with it (at least TeXworks compiles the pdf).
HTH
bye

Missing number treated as zero error when using titlesec package and tableofcontents

Whenever I use the package titlesec and later the command \tableofcontents I get the following error:
I created the following MRE below
! Missing number, treated as zero. <to be read again>}\tableofcontents
In the past this never happened, but since I installed MikTex on my new laptop, those lines below do not work anymore.
Removing the package titlesec seems to work, but I would rather know the actual reason for this problem.
\RequirePackage{fix-cm}
\documentclass[
%draft,
pdftex,
paper=a4,
%paper=portait, % Paper Setting
pagesize=auto,
fontsize=11pt, % Font Size
version=last, % Version
%headsepline, % Line after header
%footsepline, % Line before footer
]{scrartcl}
\KOMAoptions{parskip=true}
% Depth of content table
\usepackage{titlesec}
\begin{document}
\tableofcontents
\newpage
Test
\end{document}

latex error Missing $ inserted

I'm trying to use LaTeX to write my math notes. But I have some problems.
The error is written:
LaTeX error Missing $ inserted
And it doesn't compile correctly:
\documentclass[french,12pt,a4paper]{article}
\usepackage[french]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{fullpage}
\author{
Alexandre Monterroso\\
Université de Fribourg\\
}
\newtheorem{de}{Définition}[subsection]
\newtheorem{theo}{Théorème}[section]
\newtheorem{prop}[theo]{Proposition}
\begin{document}
\section{Combinatoris}
\subsection{Ordered choices}
\begin{itemize}
\item With repetition
\end{itemize}
\begin{theo}
The number of lists (a_{1}, ..., a_{k}) of k not necessarly distincts objects elements (ie. with repetition) from a set n elements is a^{k} (n, k \epsilon N).
\end{theo}
\end{document}
You need to specify math-related content in math mode. So, use
The number of lists ($a_1, \dots, a_k$) of~$k$ not necessarily dist ...
$...$ initiated and closes in-line math mode, while \[...\] initiates and closes display math mode.

Resources