-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtex2slide.sh
More file actions
executable file
·68 lines (61 loc) · 2.31 KB
/
tex2slide.sh
File metadata and controls
executable file
·68 lines (61 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
#
# Copyright 2016 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# tex2slide.sh
#
# A simple shell/Apple script to copy text from Keynote, compile it using
# pdflatex, and paste it back into Keynote as a pdf snippet. As is, the
# script works for Keynote, but it should work for Powerpoint and other
# applications by replacing Keynote below with another name.
#
# To create MacOS app, execute:
# mkdir -p Tex2Slide.app/Contents/MacOS
# cp tex2slide.sh Tex2Slide.app/Contents/MacOS/Tex2Slide
# chmod +x Tex2Slide.app/Contents/MacOS/Tex2Slide
FONTSIZEPT=32
PDFLATEX=/Library/TeX/texbin/pdflatex
OSASCRIPT=/usr/bin/osascript
WORKDIR=/tmp
FNAME="tex2slide-tmp"
TEXFNAME=$WORKDIR'/'$FNAME'.tex'
PDFFNAME=$WORKDIR'/'$FNAME'.pdf'
# Activate Keynote and copy to clipboard
$OSASCRIPT -e 'tell application "Keynote" to activate'
$OSASCRIPT -e 'tell application "System Events" to keystroke "c" using {command down}'
# Write latex file, modify to customize
cat > $TEXFNAME << EOF
\documentclass[preview]{standalone}
\usepackage[usenames]{color}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{arev}
\usepackage[T1]{fontenc}
\begin{document}
EOF
echo '\fontsize{'$FONTSIZEPT'}{40}' >> $TEXFNAME
# Alternative if pbpaste not available:
# $OSASCRIPT -e 'do shell script ("echo " & (the clipboard) & " >> $TEXFNAME")'
/usr/bin/pbpaste >> $TEXFNAME
echo '\end{document}' >> $TEXFNAME
# Compile latex file
cd $WORKDIR
$PDFLATEX $TEXFNAME
# Copy PDF from Preview to clipboard, paste into Keynote
echo "Opening preview"
/usr/bin/open -a Preview $PDFFNAME
$OSASCRIPT -e 'tell application "Preview" to activate'
$OSASCRIPT -e 'tell application "System Events" to keystroke "c" using {command down}'
$OSASCRIPT -e 'tell application "Keynote" to activate'
$OSASCRIPT -e 'tell application "System Events" to keystroke "v" using {command down}'