File: bib2pdf

package info (click to toggle)
cb2bib 2.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,584 kB
  • sloc: cpp: 28,329; sh: 516; makefile: 10
file content (136 lines) | stat: -rwxr-xr-x 3,278 bytes parent folder | download
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/sh
#-------------------------------------------------------------------------------
# bib2pdf  --  Script to convert BibTeX files to PDF
# cb2Bib Tools
#
# Copyright (C) 2005-2024 by Pere Constans
# constans@molspaces.com
#
# Improvements and modifications:
# Copyright (C) 2009 by Filippo Rusconi
# rusconi@mnhn.fr
#
# May/June 2009:
# - Added checks to ensure that the used commands are available on
#   system.
# - Make use of mktemp to create a temp directory.
#
# See LICENSE file that comes with this distribution
#
# Usage: bib2pdf input_bib output_pdf
#-------------------------------------------------------------------------------

#-------------------------------------------------------------------------------
# Init variables
#-------------------------------------------------------------------------------
# Modify accordingly, by choosing either pdflatex or latex+dvipdfm
#latexCmd=pdflatex
latexCmd=latex ; dvi2pdfCmd=dvipdfm

bibtexCmd=bibtex
#-------------------------------------------------------------------------------

# Immediately check that the needed programs are there:
"${latexCmd}" --version > /dev/null 2>&1

if [ "$?" != "0" ]
then
    echo "Program ${latexCmd} (LaTeX software) is required."
    echo "Ending processing."
    exit 1
fi

"${bibtexCmd}" --version > /dev/null 2>&1

if [ "$?" != "0" ]
then
    echo "Program ${bibtexCmd} (BibTeX software) is required."
    echo "Ending processing."
    exit 1
fi

# Special case with dvi2pdf:

if [ "x${dvi2pdfCmd}" != "x" ]
then
    "${dvi2pdfCmd}" --version | head -n2 | grep dvipdfm > /dev/null 2>&1
    if [ "$?" != "0" ]
    then
	echo "Program ${dvi2pdfCmd} (LaTeX software) is required."
	echo "Ending processing."
	exit 1
    fi	
fi


# Make sure we trap errors (we put that after the tests above because
# we need the tests to fail, in case, without exiting immediately).
set -e

# Getting filenames from command line
echo "cb2Bib Tools: Script to convert BibTeX to PDF"
if test "$#" != 2; then
  cat <<EOF
Usage: $0 input_bib output_pdf
EOF
  exit 2
fi


# Init some other variables (Modify accordingly) and create temporary
# directory.
latex_flags="-interaction=nonstopmode"
# Note that we use the mktemp utility that ensures that
# we do not overwrite any preexisting directory.
tmp_dir=$(mktemp -d --tmpdir c2b_tools_tmp.XXXXXXXX)


# Setting files
bib="$1"
pdf="$2"
work_dir="$PWD"

cat > "${tmp_dir}"/c2b_tmp.tex <<EOF
\documentclass[a4paper,10pt]{article}
%\documentclass[letterpaper,10pt]{article}
\pagenumbering{roman}
\bibliographystyle{unsrt}

\oddsidemargin 0.0in 
\evensidemargin 1.0in 
\textwidth 6.0in 
\headheight 0.0in 
\topmargin 0.in 
\textheight 9.0in 

\begin{document}

\nocite{*}
\bibliography{c2b_tmp}

\end{document}

EOF
cp "$bib" "${tmp_dir}"/c2b_tmp.bib

# LaTeX procedure (Modify accordingly)
cd "${tmp_dir}"
# There might be bibliography errors, do not stop.
set +e
"${latexCmd}" $latex_flags c2b_tmp > /dev/null 2>&1
"${bibtexCmd}" c2b_tmp
"${latexCmd}" $latex_flags c2b_tmp > /dev/null 2>&1
"${latexCmd}" $latex_flags c2b_tmp
if [ "x${dvi2pdfCmd}" != "x" ]
then
    "${dvi2pdfCmd}" c2b_tmp > /dev/null 2>&1
fi

# Make sure we trap errors.
set -e

# Clean up
cd "${work_dir}"
cp "${tmp_dir}"/c2b_tmp.pdf "$pdf"
rm -rf "${tmp_dir}"
echo "$0 ended."