My beamer presentation presents this problem Package inputenc Error: Unicode char − (U+2212)(inputenc) not set up for use with LaTeX. end{frame}
. I tried remove some elements and I see that problem appear when I use -
in equation. I’d like one hint about this problem.
documentclass[pt]{beamer}
usepackage[T1]{fontenc}
usepackage{amsmath}
usepackage[utf8]{inputenc}
usepackage[brazil]{babel}
usepackage{upgreek}
usepackage{mathtools}
usetheme{Berlin}
begin{document}
begin{frame}{Convergência - Prova}
%justifying
Sem perda de generalidade a demonstração foi focada numa partícula unidimensional. Reescrevendo a Equação, tem-se que
begin{equation}
x_i(t + 1) + alpha_1 x_i(t) + alpha_2 x_i(t − 1) = alpha_3
end{equation}
onde
begin{equation}
begin{aligned}
alpha_1 &= (1 + omega) + u(r_1 - r'_1)c_1 + u(r_2 -r'_2)c_2 + c_1r{'}_1 + c_2r'_2 \
alpha_2 &= omega \
alpha_3 &= u(r_1 - r'_1)c_1p + uc_2(r_2g - r'_2n) + c_1r'_1p + c_2r'_2n
end{aligned}
end{equation}
end{frame}
end{document}
Sorry by english
asked Mar 29, 2017 at 13:29
3
Unicode U+2212 is MINUS SIGN, which is not set up by default with inputenc
. Just add
DeclareUnicodeCharacter{2212}{-}
to your preamble, just before begin{document}
.
documentclass[pt]{beamer}
usepackage[T1]{fontenc}
usepackage{amsmath}
usepackage[utf8]{inputenc}
usepackage[brazil]{babel}
usepackage{upgreek}
usepackage{mathtools}
usetheme{Berlin}
DeclareUnicodeCharacter{2212}{-}
begin{document}
begin{frame}{Convergência - Prova}
%justifying
Sem perda de generalidade a demonstração foi focada numa partícula unidimensional. Reescrevendo a Equação, tem-se que
begin{equation}
x_i(t + 1) + alpha_1 x_i(t) + alpha_2 x_i(t − 1) = alpha_3
end{equation}
onde
begin{equation}
begin{aligned}
alpha_1 &= (1 + omega) + u(r_1 - r'_1)c_1 + u(r_2 -r'_2)c_2 + c_1r{'}_1 + c_2r'_2 \
alpha_2 &= omega \
alpha_3 &= u(r_1 - r'_1)c_1p + uc_2(r_2g - r'_2n) + c_1r'_1p + c_2r'_2n
end{aligned}
end{equation}
end{frame}
end{document}
This will do the right thing even without searching for the offending character (you possibly got it from copy-paste).
answered Mar 29, 2017 at 17:21
egregegreg
1.0m127 gold badges2539 silver badges4092 bronze badges
This blog post explains how plots from matplotlib can be exported to PGF files, which in turn can be imported into $LaTeX$ documents. All figures in this post are links that point to the source code used to generate them.
Motivation
Skip this part if you are already motivated, i.e. you know why you would want to export from matplotlib to LaTeX.
Suppose you have a Python script that produces a nice plot using matplotlib. You might save the plot with
plt.savefig('histogram.png', dpi=400)
and it will write a PNG file to the disk, which is ~141 KB in size (in the example).
However, importing this file as an image into a LaTeX document has some drawbacks. Most notably that
- the fonts of the document do not match the axes labels,
- the text is not searchable (“probability density” would not be found with
ctrl+f
), - the image gets blurry when the reader zooms in, and
- it is comparably large in file size.
The solution to all four problems is exporting a PGF file from matplotlib, so LaTeX itself can take care of rendering the figure.
Exporting Matplotlib Plots
Adjust your matplotlib script by adding the following lines after import matplotlib
:
matplotlib.use("pgf") matplotlib.rcParams.update({ "pgf.texsystem": "pdflatex", 'font.family': 'serif', 'text.usetex': True, 'pgf.rcfonts': False, })
Update the save command to write to .pgf
plt.savefig('histogram.pgf')
and make sure LaTeX is installed on the system. The command pdflatex
is needed. On Mac brew cask install mactex
does the job.
Running the script will output the histogram file in PGF format which can be imported with LaTeX.
Importing PGF with LaTeX
Place the PGF file in the LaTeX project folder and import it with the following code:
begin{figure} begin{center} input{histogram.pgf} end{center} caption{A PGF histogram from texttt{matplotlib}.} end{figure}
The figure will appear in the document.
Adjusting the Plot Size
The PGF figure might be scaled undesirably, e.g. it can be too wide. In that case I found it helpful to determine the text width textwidth
of the document with the command
usepackage{layouts} [...] printinunitsof{in}prntlen{textwidth}
and adjust the matplotlib figure based on that:
fig.set_size_inches(w=4.7747, h=3.5)
Scaling with matplotlib is better than scaling the entire PGF figure because the font sizes remain the same and match the text in the document.
References
- Blog post on the same topic by Sebastian Billaudelle
- TeX StackExchange Answer by blahdiblah: determining the text width in a document
- StackOverflow answer by Elenium: matplotlib rcParams configuration
- Matplotlib examples: histogram plot used in this post
#28446
closed
defect
(fixed)
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | blocker | Milestone: | sage-8.9 |
Component: | documentation | Keywords: | |
Cc: | strogdon | Merged in: | |
Authors: | François Bissey | Reviewers: | David Coudert |
Report Upstream: | N/A | Work issues: | |
Branch: | d5862a9 (Commits, GitHub, GitLab) | Commit: | d5862a91c732c95ac1366273c66cd8d7b445cf97 |
Dependencies: | Stopgaps: |
#28271 introduced a unicode minus sign in the documentation. It causes the pdf building of the documentation to break
! Package inputenc Error: Unicode character − (U+2212) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.65295 ... that for every (i in {1, ..., n − 1}) the ? ! Emergency stop. ... l.65295 ... that for every (i in {1, ..., n − 1}) the You may provide a definition with DeclareUnicodeCharacter
The offending minus sign is on line 1284 of the file src/sage/graphs/traversals.pyx
.
Change History (8)
Authors: | → François Bissey |
---|---|
Branch: | → u/fbissey/unicode_minus |
Commit: | → d5862a91c732c95ac1366273c66cd8d7b445cf97 |
Status: |
new → needs_review |
Reviewers: | → David Coudert |
---|---|
Status: |
needs_review → positive_review |
Priority: |
major → blocker |
---|
Branch: |
u/fbissey/unicode_minus → d5862a91c732c95ac1366273c66cd8d7b445cf97 |
---|---|
Resolution: | → fixed |
Status: |
positive_review → closed |
Note: See
TracTickets for help on using
tickets.