pax_global_header 0000666 0000000 0000000 00000000064 12352307253 0014514 g ustar 00root root 0000000 0000000 52 comment=9060584b84ead2d18201e826131b3181713405cb
gladtex-1.4.2/ 0000775 0000000 0000000 00000000000 12352307253 0013150 5 ustar 00root root 0000000 0000000 gladtex-1.4.2/CMakeLists.txt 0000664 0000000 0000000 00000002602 12352307253 0015710 0 ustar 00root root 0000000 0000000 project(gladtex)
cmake_minimum_required(VERSION 2.8.5)
find_package(ZLIB REQUIRED)
find_package(PNG REQUIRED)
find_package(GIF)
if(GIF_FOUND)
include_directories(${GIF_INCLUDE_DIR})
add_definitions(-DGIF)
endif()
include_directories(${ZLIB_INCLUDE_DIRS} ${PNG_INCLUDE_DIRS})
set(eqn2img_SRCS
eqn2img.c
)
if(WIN32)
set(eqn2img_SRCS ${eqn2img_SRCS} getopt.c)
endif()
if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS -wd4996)
endif()
add_executable(eqn2img ${eqn2img_SRCS})
target_link_libraries(eqn2img ${ZLIB_LIBRARIES} ${PNG_LIBRARIES})
if(GIF_FOUND)
target_link_libraries(eqn2img ${GIF_LIBRARIES})
endif(GIF_FOUND)
find_program(POD2MAN pod2man)
if(POD2MAN)
message(STATUS "found pod2man for generation of documentation: ${POD2MAN}")
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/gladtex.1
COMMAND ${POD2MAN} ARGS -c \"User Commands\" -r \"gladtex 1.3\" ${CMAKE_SOURCE_DIR}/gladtex.pod > ${CMAKE_BINARY_DIR}/gladtex.1)
add_custom_target(gladtex.1_custom ALL DEPENDS ${CMAKE_BINARY_DIR}/gladtex.1)
endif()
install(TARGETS eqn2img RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
install(PROGRAMS gladtex DESTINATION bin)
install(FILES eqn2img.1 DESTINATION share/man/man1)
if(POD2MAN)
install(FILES ${CMAKE_BINARY_DIR}/gladtex.1 DESTINATION share/man/man1)
endif()
gladtex-1.4.2/COPYING 0000664 0000000 0000000 00000043261 12352307253 0014211 0 ustar 00root root 0000000 0000000 For all files, except for getopt.c, the license below applies. getop.c is public
domain.
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
Copyright (C) 19yy
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) 19yy name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.
gladtex-1.4.2/README 0000664 0000000 0000000 00000004221 12352307253 0014027 0 ustar 00root root 0000000 0000000 *contents*
* License
* Installation
* Installation Hints For Windows
* Documentation
License
=======
gladTeX --- generate html with LaTeX equations embedded as images
_Copyright:_
- (C) 1999-2010 Martin G. Gulbrandsen
- (C) 2011-2013 Jonathan Daugherty (especially release 1.3)
- (C) 2013-2014 Sebastian Humenda
Credits go to
- 2013 Patrick Spendrin (patches for cmake and eqn2img to build it on Windows)
This program is distributed under the GNU GPL; for details
see the accompanying file COPYING.
Project homepage is at http://gladtex.sourceforge.net
Installation
============
Dependencies
------------
The following is needed for compiling Gladtex:
* zlib
* libgif, libpng (development headers)
* gcc and cmake (at least on GNU/Linux)and make, but see below)
* you can use cmake to use other build systems as well
* perl (for pod2man)
For Debian, you need just the command:
# apt-get install build-essential libzlib1g-dev libpng12-dev libgif-dev
# apt-get install perl cmake
The following is needed for executing gladTeX:
* a working LaTeX-distribution with the commands dvipng and latex
* zlib
* libpng, libgif
* perl
For Debian, you run:
# apt-get install perl dvipng texlive-latex-base libpng12 libgif libzlib1g
Installation using cmake
------------------------
If you have installed the requirements, and gladtex/ is your source folder
run the following commands.
p@mymachine ~/gladtex $ mkdir build && cd build
p@mymachine ~/gladtex/build $ cmake ~/gladtex -DCMAKE_INSTALL_PREFIX=/usr
p@mymachine ~/gladtex/build $ make && make install
Windows
=======
If you want to run GladTeX on Windows, you have to install cmake and a compiler
suite as visual studio. Tell cmake to export visual studio project files and use
those to build the project. To execute GladTeX you will either need perl or
compile it. For compilation, you need `pp` (accompanies perl) and execute:
$ pp -o gladtex gladtex.pl
Finaly, you have to make sure that the executables to gladtex, ghostscript,
latex and dvips are in `%PATH%`. We would currently suggest installing MikTeX.
Documentation
=============
Please use `man gladtex` for further instructions.
gladtex-1.4.2/WHATSNEW 0000664 0000000 0000000 00000006245 12352307253 0014342 0 ustar 00root root 0000000 0000000 1.4.2
- add some eval's to cope with some failures
- since there were some incompatibilies between Perl 5.10 and 5.18 in how
the cache of the generated images is stored, GladTeX now removes this file
along with all images starting with "eqn" and generates them again.
1.4.1
- remove desc.html if created and empty
1.4 - put LaTeX equations into alt tag for text-mode browsers and blind people
(and disabled images)
- if requested (-a), exclude equations longer than 80 characters in an extra
file and make the equation image a link to the longer, excluded image
alternative
- eqn2img: patch to allow building on windows
- change build system from make to cmake
- refactored gladtex code a lot to allow the usage of "use strict/use
warnings"
- fix bug where multiple equations couldn't on a single line
- rework manpage
1.3 - Un-escape common entities before processing equations
- Update man page with CSS class options
- Add support for setting the CSS class of images when the
environment is "math" or "displaymath"
- eqn2img: changed redirection syntax (from dvips to /dev/null)
for portability
- gladtex: exit with status 1 when a closing EQ tag is missing
- gladtex: print error messages to stderr instead of stdout
- Fix environment-passing to eqn2img
- Add support for a "dpi" attribute on EQ tags to customize the
DPI used for each equation
1.2 - Fixed a serious memory allocation error, pointed out by Eric J.
Francois. Also fixed several leaks.
- Added full alpha channel to PNG files (also suggested by Eric)
- The -e option was ignored, fixed (pointed out by Andr\'e Schleife)
- Added man page, contributed by Volker Schatz
1.1 - Portability fixes: Do not assume a specific location for perl
(use "env" in the shebang line) and do not rely on the bash style
"&>" redirection.
1.0 - Image alignment workaround (most browsers interpret
"ALIGN=MIDDLE" somewhat strangely, so it has been changed
to "STYLE=vertical-align: -xx")
- Added cache file, so that gladtex doesn't have to regenerate
images for equations that haven't changed.
- Added ENV option (as in ) to support environments
other than "displaymath".
- Bug fixes.
0.3 - Added BoundingBox workaround (dvips sometimes outputs wrong
BoundingBox, for instance when using \mathbb{})
- Moved the whole "LaTeX eqn to image" conversion into the C code,
turning the C program (renamed from pngmodify to eqn2img) into
a standalone utility (e.g. echo '\sqrt{2}' | eqn2img -o
eqn.png).
- Added colour options (-c -b and -t).
- Fixed bug causing segfault when adding space _above_ an image.
- Fixed image reusing bug (in 0.2 image reuse didn't work across
separate files when processing files outside startup cwd).
- And some other minor bugs and cosmetic changes.
- Makefile added to distribution
0.2 - First official release, completely rewritten code.
0.1 - Used only internally at the Dept. of Mathematics at the Univ. of Oslo
July-August 1999 (for the project "Matteknekker'n") under the name
htmleqn.
gladtex-1.4.2/eqn2img.1 0000664 0000000 0000000 00000002360 12352307253 0014575 0 ustar 00root root 0000000 0000000 .TH eqn2img
.SH Name
.PP
eqn2img \- read equation from stdin and generate image using LaTeX
.SH SYNOPSIS
.PP
.B eqn2img
[\fIOPTION\fR]...
.SH DESCRIPTION
.PP
The program reads a LaTeX maths string from standard input (stdin). The
generated image written to stdout unless a filename is specified with the \-o
option. Run eqn2img with \-f ? to list supported image formats.
.PP
This program is part of GladTeX.
.TP
\fB\-o\fR \Finame\fR
output filename
.TP
\fB\-v\fR
print verbose information
.TP
\fB\-f\fR \fIformat\fR
store images in 'format' (png by default)
.TP
\fB\-s\fR \fIn\fR
set oversampling factor for antialiasing to 'n' (4 by default)
.TP
\fB\-r\fR \fIdpi\fR
set output resolution to 'dpi' dots per inch
.TP
\fB\-p\fR \fIstring\fR
add 'string' to LaTeX preamble (e.g. \usepackage{...})
.TP
\fB\-e\fR \fIenv\fR
embed equation in \\begin{env}..\\end{env} (e.g. \-e 'align*')
.TP
\fB\-c\fR \fIcolour\fR
set foreground RGB colour (000000 by default)
.TP
\fB\-b\fR \fIcolour\fR
set background RGB colour (A0A0A0 by default, ignored for png)
.TP
\fB\-t\fR
turn transparency OFF
.SH About This Manual Page
.PP
This manual page is (C) 2014 Sebastian Humenda . It is licensed
under the same license as the program. See file COPYING for details.
gladtex-1.4.2/eqn2img.c 0000664 0000000 0000000 00000051076 12352307253 0014667 0 ustar 00root root 0000000 0000000 /* eqn2img: converts LaTeX equation to image, part of gladtex
Project homepage at http://gladtex.sourceforge.net
Copyright (C) 1999-2010 Martin G. Gulbrandsen
(C) 2014 Sebastian Humenda
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* Uncomment this for gif support */
/*#define GIF*/
#define BACKGROUND 0xFF
#define MAX(a,b) ((a)>(b) ? (a) : (b))
/* returns least integer >= a/b */
#define DIV(a,b) (((a)/(b))*(b) == (a) ? (a)/(b) : (a)/(b) + 1)
#define USAGE "\
This utility is part of\n\
gladtex version 1.4.1, Copyright (C) 1999-2010 Martin G. Gulbrandsen\n\
(C) 2014 Sebastian Humenda\n\
\n\
GladTXx comes with ABSOLUTELY NO WARRANTY. This is free software,\n\
and you are welcome to redistribute it under certain conditions;\n\
see the file COPYING for details.\n\
\n\
Usage: eqn2img [OPTION]...\n\
\n\
-o name output filename\n\
-v print verbose information\n\
-f format store images in 'format' (png by default)\n\
-s n set oversampling factor for antialiasing to 'n' (4 by default)\n\
-r dpi set output resolution to 'dpi' dots per inch\n\
-p string add 'string' to LaTeX preamble (e.g. \\usepackage{...})\n\
-e env embed equation in \\begin{env}..\\end{env} (e.g. -e 'align*')\n\
-c colour set foreground RGB colour (000000 by default)\n\
-b colour set background RGB colour (A0A0A0 by default, ignored for png)\n\
-t turn transparency OFF\n\
\n\
LaTeX maths string is read from stdin. Image written to stdout unless filename\n\
specified with -o option. Run with -f ? to list supported image formats.\n"
#include
#include
#include
#ifndef _WIN32
#include
#else
extern int optind;
extern char *optarg;
int getopt(int argc, char * const argv[], const char *optstring);
#define STDOUT_FILENO _fileno(stdout)
#define popen _popen
#define pclose _pclose
#endif
#include
#include
#ifdef GIF
#include
#endif
#define NEW(type,size) (type *) malloc(sizeof(type)*(size))
enum img_format {png
#ifdef GIF
,gif
#endif
};
struct rgb {
unsigned int red;
unsigned int green;
unsigned int blue;
};
void split_name(char *filename, char **dir, char **base, char **ext);
char *mk_basename(char *img_name);
char *mk_dirname(char *img_name);
png_structp png_initialize(FILE *fp, int *width, int *height);
png_bytepp png_read(char *filename, int *width, int *height);
png_bytepp img_modify(png_bytepp in_img, int width, int height, int supersample,
int *new_width, int *new_height, int *baseline);
int png_write(png_bytepp image, char *basename, int width, int height,
struct rgb foreground, struct rgb background, int transparency);
#ifdef GIF
int gif_write(png_bytepp image, char *basename, int width, int height,
struct rgb foreground, struct rgb background, int transparency);
#endif
int to_dvi(char *base_name, char *preamble, char *env, int verbose);
int to_ps(char *base_name, int verbose);
int to_png(char *base_name, int dpi, int supersample, int verbose);
int main(int argc, char **argv)
{
char c;
enum img_format format = png;
int supersample = 4;
char *img_name = NULL;
char *basename = NULL;
char *dirname = NULL;
char *extname = NULL;
char *png_inname = NULL;
char *env = NULL;
png_bytepp in_image, out_image;
int height, width;
int new_height, new_width, baseline;
int retval=0;
int verbose=0;
int transparency=1;
int dpi=100;
struct rgb foreground = {0,0,0};
struct rgb background = {0xA0,0xA0,0xA0};
char *preamble = NULL;
int i;
/* parse command-line options */
while((c = getopt(argc, argv, "f:s:o:e:tvc:b:r:p:")) != EOF) {
switch(c) {
case 'f':
if(!strcmp("png", optarg)) {
format = png;
}
#ifdef GIF
else if(!strcmp("gif", optarg)) {
format = gif;
}
#endif
else if(optarg[0]=='?') {
printf("Supported image formats: png%s",
#ifdef GIF
", gif"
#endif
"\n");
return 0;
}
else {
fprintf(stderr, "\nUnknown format '%s'\n", optarg);
return 1;
}
break;
case 's':
supersample = atoi(optarg);
if(supersample <= 0) {
fprintf(stderr, "\nOversampling factor %s is not a positive integer\n", optarg);
return 1;
}
break;
case 'o':
img_name = NEW(char, strlen(optarg)+1);
assert(img_name);
strcpy(img_name, optarg);
break;
case 'e':
env = NEW(char, strlen(optarg)+1);
assert(env);
strcpy(env, optarg);
break;
case 'v':
verbose = 1;
break;
case 't':
transparency = 0;
break;
case 'c':
sscanf(optarg, "%02x%02x%02x", &foreground.red, &foreground.green, &foreground.blue);
break;
case 'b':
sscanf(optarg, "%02x%02x%02x", &background.red, &background.green, &background.blue);
break;
case 'p':
preamble = NEW(char, strlen(optarg)+1);
assert(preamble);
strcpy(preamble, optarg);
break;
case 'r':
dpi = atoi(optarg);
break;
default:
printf(USAGE);
return 0;
}
}
if(argc != optind) {
printf(USAGE);
return 0;
}
if(!preamble) {
preamble = NEW(char, 1);
assert(preamble);
preamble[0] = '\0';
}
if(!env) {
env = NEW(char, 12);
assert(env);
strcpy(env, "displaymath");
}
if(img_name) {
split_name(img_name, &dirname, &basename, &extname);
if(extname)
sprintf(img_name, "%s.%s", basename, extname);
else
img_name = basename;
}
else {
basename = NEW(char, 7);
assert(basename);
strcpy(basename, "noname");
dirname = NEW(char, 2);
assert(dirname);
strcpy(dirname, ".");
}
retval = chdir(dirname);
assert(!retval);
/* convert LaTeX equation text to image */
if(to_dvi(basename, preamble, env, verbose) ||
to_ps(basename, verbose) ||
to_png(basename, dpi, supersample, verbose)) {
return 1;
}
/* read input png file */
png_inname = NEW(char, strlen(basename)+8);
assert(png_inname);
sprintf(png_inname, "%s.ps.png", basename);
in_image = png_read(png_inname, &width, &height);
unlink(png_inname);
if(!in_image) {
fprintf(stderr, "\nError reading '%s'\n", png_inname);
return 1;
}
/* clean up */
free(preamble);
free(dirname);
free(basename);
free(env);
free(png_inname);
/* process image */
out_image = img_modify(in_image, width, height, supersample, &new_width, &new_height, &baseline);
for(i=0; i Writing png image");
retval = png_write(out_image, img_name, new_width, new_height, foreground, background, transparency);
break;
#ifdef GIF
case gif:
if(verbose)
fprintf(stderr, " -> Writing gif image");
retval = gif_write(out_image, img_name, new_width, new_height, foreground, background, transparency);
break;
#endif
}
/* clean up */
for(i=0; i "dir" + "base" + "ext"
"/base.ext" -> "" + "base" + "ext"
"base.ext" -> "." + "base" + "ext"
"dir/base" -> "dir" + "base" + NULL
"dir/base." -> "dir" + "base + ""
Memory for these strings is allocated by this function.
*/
void split_name(char *filename, char **dir, char **base, char **ext)
{
char *dot, *slash;
slash = strrchr(filename, '/');
if(slash==NULL) {
*dir = NEW(char,2);
assert(*dir);
strcpy(*dir, ".");
}
else {
*dir = NEW(char, slash-filename+1);
assert(*dir);
strncpy(*dir, filename, slash-filename);
(*dir)[slash-filename] = '\0';
filename = slash+1; /* advance pointer to after slash */
}
dot = strrchr(filename, '.');
if(dot==NULL) {
*base = NEW(char, strlen(filename)+1);
assert(*base);
strcpy(*base, filename);
*ext = NULL;
}
else {
*base = NEW(char, dot-filename+1);
assert(*base);
strncpy(*base, filename, dot-filename);
(*base)[dot-filename] = '\0';
filename = dot+1;
*ext = NEW(char, strlen(filename)+1);
assert(*ext);
strncpy(*ext, filename, strlen(filename));
(*ext)[strlen(filename)] = '\0';
}
}
/*
input:
filename
output:
width, height
returns read png image, or NULL on error
*/
png_bytepp png_read(char *filename, int *width, int *height)
{
png_byte bit_depth, color_type;
png_bytepp image;
png_structp png_ptr;
png_infop info_ptr;
int row;
FILE *fp;
fp = fopen(filename, "rb");
if(!fp)
return NULL;
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
assert(png_ptr);
info_ptr = png_create_info_struct(png_ptr);
assert(info_ptr);
if(setjmp(png_jmpbuf(png_ptr))) {
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
fclose(fp);
return NULL;
}
png_init_io(png_ptr, fp);
png_read_info(png_ptr, info_ptr);
/* change pixel encoding to 8 bits grayscale */
color_type = png_get_color_type(png_ptr, info_ptr);
bit_depth = png_get_bit_depth(png_ptr, info_ptr);
if(bit_depth < 8)
png_set_packing(png_ptr);
if(bit_depth == 16)
png_set_strip_16(png_ptr);
if(color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
png_set_expand(png_ptr);
if(color_type != PNG_COLOR_TYPE_GRAY) {
fprintf(stderr, "\nInput file is not grayscale.\n");
return NULL;
}
png_read_update_info(png_ptr, info_ptr);
*width = png_get_image_width(png_ptr, info_ptr);
*height = png_get_image_height(png_ptr, info_ptr);
image = NEW(png_bytep, *height);
assert(image);
for(row=0; row<*height; row++) {
image[row] = NEW(png_byte, *width);
assert(image[row]);
}
png_read_image(png_ptr, image);
png_read_end(png_ptr, NULL);
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
fclose(fp);
return image;
}
/*
get_pixel
Returns the pixel color at coordinates (row, col). Negative
coordinates and coordinates larger than width/height are
allowed, and will return bg_color.
*/
png_byte get_pixel(png_bytepp img, int col, int row, int width, int height, png_byte bg_color)
{
if(row<0 || col<0 || row>=height || col>=width)
return bg_color;
return img[row][col];
}
/*
img_modify does the following:
- find 'leading dot' in in_img (i.e. some non-white area in the leftmost end:
the perl script prepends a . (full stop) to the equation being processed)
- copy everything to the right of the dot to out_img (returned value), while
downscaling+antialiasing the image (simply by averaging a 'supersample' times
'supersample' block to a single pixel)
- return (in "baseline") the number of pixels from the bottom of the (downscaled)
image to the baseline of the equation
input:
in_img, widt, height, supersample
output:
new_width, new_height, baseline
returns new png image
*/
png_bytepp img_modify(png_bytepp in_img, int width, int height, int supersample,
int *new_width, int *new_height, int *baseline)
{
int row, col;
int dot_found = 0;
int edge_found = 0;
int row_count = 0;
long row_sum = 0;
int row_center;
int col_start = 0;
png_bytepp out_img;
assert(in_img);
/* find dot: vertical center and horisontal end
(maybe it's better to find vertical end instead of center?)
also wipe out dot */
for(col=0; col < width; col++) {
int empty_col = 1;
for(row=0; row < height; row++) {
if((in_img[row])[col] != BACKGROUND) {
(in_img[row])[col] = BACKGROUND;
dot_found = 1;
empty_col = 0;
row_count++;
row_sum += row;
}
}
if(dot_found && empty_col) {
/* col is 1st blank column after dot */
col_start = col;
break;
}
}
if(col == width) {
fprintf(stderr, "\nImage doesn't start with a dot\n");
exit(1);
}
/* the next step is a workaround: sometimes dvips produces a wrong
boundingbox in the ps-file (I've seen this when using the \mathbb
font), resulting in a too wide image (the height is correct but
the box is extended to the right). to solve this we remove any
blank area to the right */
edge_found=0;
for(col=width-1; col>=0 && !edge_found; col--) {
for(row=0; row < height; row++) {
if((in_img[row])[col] != BACKGROUND) {
width = col+supersample; /* this is the true width (we add a small border) */
edge_found = 1;
break;
}
}
}
/* row_sum/row_count should be the centre of the "leading dot", but
the dot itself lies above the baseline, so we add a few pixels */
row_center = row_sum/row_count+supersample*2;
*new_height = DIV(height, supersample);
*new_width = DIV(width-col_start, supersample);
*baseline = DIV(height-row_center,supersample);
/* allocate memory for new image and initialize to all background */
out_img = NEW(png_bytep, *new_height);
assert(out_img);
for(row=0; row < *new_height; row++) {
out_img[row] = NEW(png_byte, *new_width);
assert(out_img[row]);
memset(out_img[row], BACKGROUND, *new_width);
}
/* I guess the following could be done more efficiently, but this doesn't
seem to be the bottle neck anyway (disc i/o is) */
for(row=0; row < *new_height; row++) {
for(col=0; col < *new_width; col++) {
int delta, epsilon;
long pixel_sum = 0;
for(delta=0; delta < supersample; delta++) {
for(epsilon=0; epsilon < supersample; epsilon++) {
pixel_sum += get_pixel(in_img, col_start + supersample*col + epsilon,
supersample*row + delta,
width, height, BACKGROUND);
}
}
out_img[row][col] = pixel_sum/(supersample*supersample);
}
}
return out_img;
}
/* write image to png file */
int png_write(png_bytepp image, char *img_name, int width, int height,
struct rgb foreground, struct rgb background, int transparency)
{
FILE *fp=NULL;
int i;
png_byte trans[256];
png_structp png_ptr;
png_color pal[256];
png_infop info_ptr;
for(i=0; i<256; i++) {
if(transparency) {
pal[i].red = foreground.red;
pal[i].green = foreground.green;
pal[i].blue = foreground.blue;
trans[i] = 255-i;
}
else {
pal[i].red = (i*background.red + (255-i)*foreground.red)/255;
pal[i].green = (i*background.green + (255-i)*foreground.green)/255;
pal[i].blue = (i*background.blue + (255-i)*foreground.blue)/255;
trans[i] = 255;
}
}
if(img_name) {
fp = fopen(img_name, "wb");
if(!fp)
return -1;
}
else
fp = stdout;
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
assert(png_ptr);
info_ptr = png_create_info_struct(png_ptr);
assert(info_ptr);
/* error handling, libpng longjmps here on any error */
if(setjmp(png_jmpbuf(png_ptr))) {
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
fclose(fp);
return -1;
}
png_init_io(png_ptr, fp);
png_set_IHDR(png_ptr, info_ptr, width, height, 8, PNG_COLOR_TYPE_PALETTE,
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
png_set_PLTE(png_ptr, info_ptr, pal, 256);
png_set_tRNS(png_ptr, info_ptr, trans, 256, NULL);
png_write_info(png_ptr, info_ptr);
png_write_image(png_ptr, image);
png_write_end(png_ptr, NULL);
png_destroy_write_struct(&png_ptr, &info_ptr);
return 0;
}
/* write image to gif file */
#ifdef GIF
int gif_write(png_bytepp image, char *img_name, int width, int height,
struct rgb foreground, struct rgb background, int transparency)
{
GifFileType *fp;
GifColorType pal[256];
int i, row;
ColorMapObject *color_map;
unsigned char gc_ext[5] = { /* graphic control extension (to get transparent background) */
0x01, /* flags: transparency color flag on */
0x00, /* delay time */
0x00, /* delay time cntd */
BACKGROUND, /* transparent color index */
0x00 /* block terminator (probably not needed?) */
};
if(img_name) {
fp = EGifOpenFileName(img_name, 0);
if(!fp)
return -1;
}
else
fp = EGifOpenFileHandle(STDOUT_FILENO);
for(i=0; i<256; i++) {
pal[i].Red = (i*background.red + (255-i)*foreground.red)/255;
pal[i].Green = (i*background.green + (255-i)*foreground.green)/255;
pal[i].Blue = (i*background.blue + (255-i)*foreground.blue)/255;
}
color_map = MakeMapObject(256, pal);
/* EGifSetGifVersion("89a"); this causes segfault (but is really required for transparency, I think) */
EGifPutScreenDesc(fp, width, height, 256, 255, color_map);
if(transparency) {
EGifPutExtension(fp, 0xF9, 4, gc_ext); /* this sets transparent color to background */
}
EGifPutImageDesc(fp, 0, 0, width, height, 0, color_map);
for(row=0; row dvi");
tex_file = fopen(tex_name, "w");
fprintf(tex_file, "\\nonstopmode\n"
"\\documentclass[12pt]{article}\n"
"\\pagestyle{empty}\n"
"%s\n"
"\\begin{document}\n"
"\\begin{%s}\n"
".",
preamble, env);
/* copy equation text from stdin to tex_file */
while(!feof(stdin)) {
char buf[256];
int n;
n = fread(buf, 1, 256, stdin);
fwrite(buf, 1, n, tex_file);
}
fprintf(tex_file, "\\end{%s}\n\\end{document}\n", env);
fclose(tex_file);
cmd = NEW(char, strlen(tex_name) + 19);
assert(cmd);
sprintf(cmd, "latex %s > /dev/null", tex_name);
retval = system(cmd);
unlink(tex_name);
sprintf(tex_name, "%s.aux", basename);
unlink(tex_name);
if(retval) {
sprintf(tex_name, "%s.dvi", basename);
unlink(tex_name);
fprintf(stderr, "\nError running LaTeX\n");
return -1;
}
sprintf(tex_name, "%s.log", basename);
unlink(tex_name);
free(tex_name);
free(cmd);
return 0;
}
int to_ps(char *basename, int verbose) {
char *cmd;
if(verbose)
fprintf(stderr, " -> ps");
cmd = NEW(char, 2*strlen(basename) + 46);
sprintf(cmd, "dvips -E -o %s.ps %s.dvi > /dev/null 2> /dev/null", basename, basename);
if(system(cmd)) {
fprintf(stderr, "\nError running dvips\n");
return -1;
}
sprintf(cmd, "%s.dvi", basename);
unlink(cmd);
free(cmd);
return 0;
}
int to_png(char *basename, int dpi, int supersample, int verbose) {
char *cmd;
int start_x, start_y, end_x, end_y;
int xsize, ysize, xoffset, yoffset;
int retval;
FILE *grep, *gs;
if(verbose)
fprintf(stderr, " -> png");
cmd = NEW(char, strlen(basename)+25);
sprintf(cmd, "grep \"%%BoundingBox\" %s.ps", basename);
grep = popen(cmd, "r");
retval = fscanf(grep, "%%%%BoundingBox: %i %i %i %i", &start_x, &start_y, &end_x, &end_y);
assert(retval != EOF);
pclose(grep);
free(cmd);
xsize = 1 + ((end_x - start_x) * dpi)/72;
ysize = 1 + ((end_y - start_y) * dpi)/72;
xsize *= supersample;
ysize *= supersample;
xoffset = start_x;
yoffset = start_y;
cmd = NEW(char, strlen(basename)+200); /* I didn't count those 200.. */
sprintf(cmd, "gs -sDEVICE=pngmono -sOutputFile=%s.ps.png -r%i -g%ix%i -q - %s.ps",
basename, dpi*supersample, xsize, ysize, basename);
gs = popen(cmd, "w");
fprintf(gs, "%i neg %i neg translate\n", xoffset, yoffset);
pclose(gs);
sprintf(cmd, "%s.ps", basename);
unlink(cmd);
free(cmd);
return 0;
}
gladtex-1.4.2/getopt.c 0000664 0000000 0000000 00000007204 12352307253 0014621 0 ustar 00root root 0000000 0000000 /*
* Public Domain getopt - history below
*
*/
/*
* From: gwyn@brl-tgr.ARPA (Doug Gwyn ) Newsgroups: net.sources
* Subject: getopt library routine Date: 30 Mar 85 04:45:33 GMT
*/
/*
* getopt -- public domain version of standard System V routine
*
* Strictly enforces the System V Command Syntax Standard; provided by D A
* Gwyn of BRL for generic ANSI C implementations
*
* #define STRICT to prevent acceptance of clustered options with arguments
* and ommision of whitespace between option and arg.
*/
/*
* Modified by Manuel Novoa III on 1/5/01 to use weak symbols.
* Programs needing long options will link gnu_getopt instead.
*/
/*
* Last public domain version 1.5 downloaded from uclibc CVS:
* http://www.uclibc.org/cgi-bin/cvsweb/uClibc/libc/unistd/getopt.c
* on 2003-02-18 by Dave Beckett and tidied:
* Ran through "indent getopt.c -gnu" then fixed up the mess
* Removed register - compilers are smart these days
* ANSI-fied the declarations
* Prefixed with raptor_ so that it doesn't clash with any getopt
* linked in later.
* on 2013-11-05 changed by Patrick Spendrin:
* remove unneeded code
*/
#include
#include
int opterr; /* error => print message */
int optind; /* next argv[] index */
int optopt; /* Set for unknown arguments */
char *optarg; /* option parameter if any */
/*
* Err:
* program name argv[0]
* specific message
* defective option letter
*/
static int
Err (char *name, const char *mess, int c) /* returns '?' */
{
optopt = c;
if (opterr)
{
(void) fprintf (stderr, "%s: %s -- %c\n", name, mess, c);
}
return '?'; /* erroneous-option marker */
}
int
getopt (int argc, char * const argv[], const char *optstring)
{
static int sp = 1; /* position within argument */
int osp; /* saved `sp' for param test */
#ifndef STRICT
int oind; /* saved `optind' for param test */
#endif
int c; /* option letter */
char *cp; /* -> option in `optstring' */
optarg = NULL;
/* initialise getopt vars */
if (optind == 0)
{
optind = 1;
opterr = 1;
optopt = 1;
optarg = NULL;
}
if (sp == 1)
{ /* fresh argument */
if (optind >= argc /* no more arguments */
|| argv[optind][0] != '-' /* no more options */
|| argv[optind][1] == '\0' /* not option; stdin */
)
return EOF;
else if (strcmp (argv[optind], "--") == 0)
{
++optind; /* skip over "--" */
return EOF; /* "--" marks end of options */
}
}
c = argv[optind][sp]; /* option letter */
osp = sp++; /* get ready for next letter */
#ifndef STRICT
oind = optind; /* save optind for param test */
#endif
if (argv[optind][sp] == '\0')
{ /* end of argument */
++optind; /* get ready for next try */
sp = 1; /* beginning of next argument */
}
if (c == ':'
|| c == '?' /* optstring syntax conflict */
|| (cp = strchr (optstring, c)) == NULL) /* not found */
{
return Err (argv[0], "illegal option", c);
}
if (cp[1] == ':')
{ /* option takes parameter */
#ifdef STRICT
if (osp != 1)
{
return Err (argv[0], "option must not be clustered", c);
}
/* reset by end of argument */
if (sp != 1)
{
return Err (argv[0], "option must be followed by white space", c);
}
#else
if (oind == optind)
{ /* argument w/o whitespace */
optarg = &argv[optind][sp];
sp = 1; /* beginning of next argument */
}
else
#endif
if (optind >= argc)
{
return Err (argv[0], "option requires an argument", c);
}
else /* argument w/ whitespace */
optarg = argv[optind];
++optind; /* skip over parameter */
}
return c;
}
gladtex-1.4.2/gladtex 0000775 0000000 0000000 00000041166 12352307253 0014536 0 ustar 00root root 0000000 0000000 #!/usr/bin/perl
# vim:expandtab sts=4 ts=4 shiftwidth=4 number :
# gladtex: Reads a 'htex' file (html with LaTeX maths embedded in )
# and produces html with equations substituted by images.
# Project homepage at http://gladtex.sourceforge.net
# Copyright (C) 1999-2010 Martin G. Gulbrandsen
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# note: the utility 'eqn2img' should accompany this script,
# and must be callable from this script.
use warnings;
use strict;
use IPC::Open2;
use Cwd;
use Getopt::Std;
use Storable;
use File::Spec;
our $img_dir = "."; # default values
our $img_dir_relative = ".";
our $dpi = 100;
our $supersample = 4;
our $format = "png";
my $verbose = 0;
our $foreground = "000000";
our $background = "A0A0A0";
our $transparency = 1;
our $environment = "displaymath";
our $blockMathClass = "displaymath";
our $inlineMathClass = "inlinemath";
my $preamble = "
\\usepackage{amsmath}
\\usepackage{amssymb}
";
our $usage = "gladtex version 1.2, Copyright (C) 1999-2010 Martin G. Gulbrandsen
gladtex comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions;
see the file COPYING for details.
Project homepage at http://gladtex.sourceforge.net
Usage: gladtex [OPTION]... [FILE]...
Convert htex file (HTML with LaTeX equations) to html with images
-a save text alternatives for images which are too long for the alt
attribute into a single separate file and link images to it
-b colour set background RGB colour ($background by default)
-c colour set foreground RGB colour ($foreground by default)
-d path store image files in 'path' (current directory is default), affects
also place of image alternatives
-e env embed LaTeX code in \\begin{env}..\\end{env} ($environment by default)
-f format store images in 'format' (png by default)
-i class CSS class to assign to inline math (default: 'inlinemath')
-l class CSS class to assign to block-level math (default: 'displaymath')
-p string add 'string' to LaTeX preamble (e.g. \\usepackage{...})
-r dpi set resolution (size of images) to 'dpi' ($dpi by default)
-s n set oversampling factor for antialiasing to 'n' ($supersample by default)
-t turn transparency OFF
-u url url to image files above (relative links are default)
-v print verbose information
Output files:
*.html copy of input FILE(s), with .. tags substituted
filename is same as input file, with the extension replaced
eqn???.png equation images (png extension is example only, see -f option)
Input files may not have .html extension, .htex is required.
";
$| = 1; # flush output after every print, causes better feedback with -v flag
my $img_name = "eqn000";
# --- sub: rel_name ---
# usage: rel_name $src, $dest;
# $src and $dest should be absolute paths
# returns: relative path to $dest, as seen from $src
sub rel_name {
my @src = split /\//, shift;
my @dest = split /\//, shift;
my $path;
my $i = 0;
# let $i = first level where $src and $dest doesn't match
for (
$i = 0 ;
$i <= $#src and $i <= $#dest and $src[$i] eq $dest[$i] ;
$i++
)
{
}
$path = "../" x ( $#src - $i + 1 );
for ( ; exists $dest[$i] ; $i++ ) {
$path .= "$dest[$i]/";
}
return $path;
}
# --- sub: full_name ---
# usage: full_name $src, $dest
# $src should be some absolute path
# $dest may be relative (as seen from $src) or absolute
# returns absolute path to $dest, as seen from $src (without trailing /)
sub full_name {
my $src = shift;
my $dest = shift;
# add trailing / if not present $dest .= "/" unless $dest =~ /\/$/;
# if not absolute path, add $src
$dest = $src . "/$dest" unless $dest =~ /^\//;
# remove ./
$dest =~ s/\.\///g;
# remove //
while ( $dest =~ s{//}{/}g ) { }
# remove ../
while ( $dest =~ s{/([^/]*/)\.\./}{$1}g ) { }
# remove trailing /
$dest =~ s/\/$//;
return $dest;
}
# --- Parse command line options ---
our %options = ();
getopts( 'f:r:s:d:u:vtc:b:p:e:l:i:a', \%options );
if ( $#ARGV < 0 ) {
print $usage;
print `eqn2img -f?`; # this prints list of supported formats
exit;
}
$img_dir = $options{d} if $options{d};
$dpi = $options{r} if $options{r};
$supersample = $options{s} if $options{s};
$format = $options{f} if $options{f};
$verbose = $options{v} if $options{v};
$transparency = 0 if $options{t};
$preamble .= "$options{p}\n" if $options{p};
$foreground = $options{c} if $options{c};
$background = $options{b} if $options{b};
$environment = $options{e} if $options{e};
$blockMathClass = $options{l} if $options{l};
$inlineMathClass = $options{i} if $options{i};
our $url;
our %history;
if ( $options{u} ) {
$url = $options{u};
$url .= "/" unless $url =~ /\/$/;
if ( !$options{d} ) {
print "\nWarning: -u option present, but no -d\n\n";
}
}
$options{t} =
0; # just do something with $options{t} to avoid 'possible typo' warning
# todo: add validation of options
if ( $options{d} and !defined $url ) {
$img_dir_relative = $img_dir;
$img_dir = full_name( getcwd(), $img_dir );
if ( !-d $img_dir ) {
unless ( mkdir $img_dir ) {
die "Unable to create $img_dir.\n";
}
}
}
# read in cached history
if ( $options{d} and -r "$img_dir/gladtex.cache" ) {
print "Retrieving cache\n" if $verbose;
eval '%history = %{ retrieve("$img_dir/gladtex.cache") };';
if($@) {
# if it exists, but was not readable, just remove it and start from the
# beginning
print "Old GladTeX cache was not readable, removed; also removing all equations.\n";
opendir(DIR, "$img_dir") || die "Can't open directory: $!\n";
while( my $fn = readdir(DIR) ) {
if( $fn =~ /^eqn/ ) {
print "Remove " . File::Spec->catdir( $img_dir, $fn) . "\n" if $verbose;
eval 'unlink( File::Spec->catdir( $img_dir, $fn ) )'; warn $@ if $@;
}
}
unlink( "$img_dir/gladtex.cache" );
%history = ();
}
}
# empty desc.html, if used:
if($options{a}) {
open( DESCFILE, ">", File::Spec->catdir( $img_dir, 'desc.html' ) );
print DESCFILE "\n";
close( DESCFILE );
}
my $desc_file_used = 0;
# --- Process input files ---
print "Processing ", $#ARGV + 1, " files\n" if $verbose;
our $startup_cwd = getcwd();
# all variables which are used in the following big loop construction; those
# were not declared in an older version of the script, but they need to for "use
# strict"
our ( $file, $directory, $basename, $full_dir );
my ( $extension, $eqn2img_opt );
my ( $img_src, $dimensions );
my $pid;
my $id_number=0;
# replace those $this_* through the correct variables later
our $this_preamble = $preamble;
our $this_foreground = $foreground;
our $this_background = $background;
our $this_environment = $environment;
our $this_dpi = $dpi;
our $this_css_class = $inlineMathClass;
foreach $file (@ARGV) {
( $directory, $basename, $extension ) =
$file =~ /(.*?)\/*([^\/]*?)\.([^\/]*)$/;
$directory or $directory = ".";
$basename or $basename = "noname";
$extension or $extension = "htex";
$extension eq "html"
and die "Don't use .html extension, .htex is required.";
$full_dir = full_name( $startup_cwd, $directory );
if ( getcwd() ne $full_dir ) {
if ( !$options{d} and %history ) {
print "Storing cache\n" if $verbose;
store( \%history, "gladtex.cache" );
undef %history;
}
chdir $full_dir;
$img_name = "eqn000" if !$options{d};
}
if ( !$options{d} and !%history ) {
if ( -r "gladtex.cache" ) {
print "Retrieving cache\n" if $verbose;
%history = %{ retrieve("gladtex.cache") };
}
}
open( INPUT, "$basename.$extension" ) or die "Cannot open $file";
open( OUTPUT, ">$basename.html" ) or die "Cannot open $basename.html";
print "\n$file -> $basename.html\n" if $verbose;
my ($start_line, $end_line) = 0;
our $line = "";
while(not eof INPUT) {
$line = ;
$start_line++;
$end_line = $start_line;
# search for tag (the s option is needed to avoid loosing linebreak at end of line)
while ( $line =~ /(.*?)(.*)/is ) {
my $equation = "";
my $alt_equation;
my $alt_long_equation="";
my $append_space = 0;
print OUTPUT $1; # everything before tag
my $options = $2; # anything between ''
$line = $3; # the rest
# scan options within tag
my $key;
while ( $options =~ /\s*?(\S*?)=\s*(\"(.*?)\"|\'(.*?)\'|(\S*))/g )
{ # should whitespace be allowed around equal sign?
$key = $1;
# only one of these will be defined
my $value;
$value = $3 if defined $3; # "value"
$value = $4 if defined $4; # 'value'
$value = $5 if defined $5; # value (no quotation marks)
# is there a better way to scan for key/value pairs?
foreach ($key) { # may add more options here when needed..
/^preamble/i and $this_preamble .= "$value\n";
/^color/i and $this_foreground = $value;
/^bgcolor/i and $this_background = $value;
/^env/i and $this_environment = $value;
/^dpi/i and $this_dpi = $value;
}
}
if ( $this_environment eq "displaymath" ) {
$this_css_class = $blockMathClass;
}
elsif ( $this_environment eq "math" ) {
$this_css_class = $inlineMathClass;
}
# read equation until is found
my $before;
my $after;
while (
not( ( $before, $after ) = ( $line =~ /(.*?)<\/eq>(.*?)$/is ) )
)
{
$equation .= "$line";
if ( eof INPUT ) {
print STDERR "Closing tag not found in equation started at line $start_line\n";
# todo: cleanup
exit 1;
}
$line = ;
$end_line++;
}
$equation .= $before; # everything before
if($after eq "") {
$append_space = 1;
}
$line = $after;
# save equation for later use in alt tag / outsourced description
$alt_equation = $equation;
# replace " in alt tag:
$alt_equation =~ s/"/"/g;
if ( length($alt_equation) > 80 and $options{a}) {
$alt_equation = substr( $alt_equation, 0, 76 ) . " ...";
$alt_long_equation = $equation;
$id_number++;
}
# strip whitespace: this makes 'history' stronger and removes linebreak
# trouble (a paragraph can't end within $$..$$ in latex)
$equation =~ s/\s+/ /g;
# Resolve entities in the equation, since the document
# ought to be well-formed HTML.
$equation =~ s/>/>/g;
$equation =~ s/</{"opt"} eq $eqn2img_opt )
{
print "Reusing image\n" if $verbose;
}
else {
while ( -e "$img_dir/$img_name.$format" ) { $img_name++ }; # never overwrite an image
print "$img_dir/$img_name: " if $verbose;
$pid = open2( \*eqn2img_out, \*eqn2img_in,
"eqn2img $eqn2img_opt -o '$img_dir/$img_name.$format'" );
print eqn2img_in $equation;
close eqn2img_in;
$dimensions = ;
waitpid $pid,
0; # close seems not to set $? when using open2, why is that?
if ($?) {
print STDERR
"Error processing equation starting at line $start_line:\n",
$equation, "\n";
print STDERR "See ${img_dir}/${img_name}.log for details\n";
exit 1;
}
close eqn2img_out;
print ", done.\n" if $verbose;
$history{$equation}->{"opt"} = $eqn2img_opt;
$history{$equation}->{"img"} = "$img_name.$format";
$history{$equation}->{"dim"} = $dimensions;
}
# if $alt_long_equation is != 0, wrap img in a link
if($alt_long_equation ne "" and $options{a}) {
print OUTPUT "catdir( $img_dir_relative,
'desc.html' ) . "#" . $id_number . "\">";
}
print OUTPUT " {"img"} . "\" "
. $history{$equation}->{"dim"}
. " alt=\""
. $alt_equation . "\" />";
if($append_space) {
print OUTPUT " ";
}
# add
if($alt_long_equation ne "" and $options{a}) {
print OUTPUT "\n";
}
# write alt_long_equation out, if appropriate
if ( $alt_long_equation ne "" ) {
if ( $options{a} ) {
$desc_file_used = 1;
open( DESCFILE, ">>",
File::Spec->catdir( $img_dir, 'desc.html' ) );
print DESCFILE "
$alt_long_equation
\n";
close(DESCFILE);
}
}
}
print OUTPUT "$line";
$start_line = $end_line;
}
}
close(INPUT);
close(OUTPUT);
sub Shutdown {
### write out data
## write out HTML ending for desc.html
if($options{a}) {
if($desc_file_used) {
open( DESCFILE, ">>", File::Spec->catdir( $img_dir, 'desc.html' ) );
print DESCFILE "\n";
close(DESCFILE);
}
}
## write out cache, if apppropriate
# write history cache
if(%history) {
print "Storing cache\n" if $verbose;
store( \%history, File::Spec->catdir( $img_dir, "gladtex.cache") );
}
## remove desc.html, if empty
if(!$desc_file_used) {
unlink(File::Spec->catdir( $img_dir, 'desc.html' ));
}
# if no gladtex cache was written, no equations and no desc.html, the
# img_dir will be empty, remove it
my $i=0;
opendir(DIR, "$img_dir") or die "Cant open $img_dir: $!\n";
my @files = readdir(DIR);
foreach $file(@files) {
unless ($file =~ /^[.][.]?\z/) {
$i++;
}
}
if ($i == 0) {
rmdir($img_dir);
}
closedir(DIR);
}
Shutdown();
gladtex-1.4.2/gladtex.pod 0000664 0000000 0000000 00000017245 12352307253 0015315 0 ustar 00root root 0000000 0000000
=pod
=head1 NAME
gladtex - generate html with LaTeX equations embedded as images
=head1 SYNOPSIS
gladtex [options] [ ...]
=head1 DESCRIPTION
Reads a 'htex' file (html with LaTeX maths embedded in
EEQEE/EQE) and produces html with equations substituted by
images.
=head1 QUICK START
Write HTML code as usual, but use LaTeX equations within the tags
EEQE..E/EQE. Don't use .html extension, .htex is recommended.
Now, run:
gladtex -v myfile.htex
Or, to process multiple files:
gladtex -v *htex
The -v option is not mandatory, but gives you more feedback. If there
are no LaTeX errors, this will generate the file myfile.html (or
similar) and numerous eqn???.png files, which contain images of your
equations. The HTML file generated is a copy of yours, but the
equations are substituted by links to the image files.
If you prefer gif files, add the option "-f gif".
gladTeX tries to avoid regenerating identical image files. To achieve
this, a cache file (gladtex.cache) is used, containing the equations
used for generating each image. If you delete the image files before
rerunning gladTeX, you should also delete the cache file (gladTeX never
deletes an image file).
If your HTML contains more than a couple of equations, it is a good
idea to place equation images in a separate directory with the -d
option. With this option turned on, the cache file is also moved to
that directory.
=head1 OPTIONS
You can optain the command-line help using gladTeX without options.
=over
=item B<-a>
Save text alternatives for images which are too long for the alt attribute into
a single separate file and link images to it. In -attributes, you can
only have up to 255 characters. Since equations with line breaks / long
equations don't fit in there, this switch allows outsourcing in a file called
desc.html in the directory specified with -d or the current directory by
default.
=item B<-b> I
Set background colour in RGB manner. This option can also be set indivdually
for each equation by writing EEQ BGCOLOR="..."E in the htex file. For
PNG format with transparency on, this option has no effect. For GIF format
(which does not support alpha channel, as far as I know), antialiasing is done
from the foreground color (-c option) to the background colour, so the
background colour should be set even with transparency on.
=item B<-c> I
Set foreground colour in RGB manner. For instance "-c 00FFFF" gives yellow
text. This option can also be set indivdually for each equation by writing
EEQ COLOR="..."E in the htex file. See also -b option.
=item B<-d> I
Store image files in the path given. The image links in the generated html
file(s) will be made relative. If you need absolute links, use the -u option in
addition.
=item B<-e> I
Use the specified LaTeX environment instead of "displaymath" when generating
the image. This option can also be set individually for each equation by
writing EEQ ENV="env"E.
=item B<-f> I
Use the specified image format in output files. Formats
supported may depend on compile-time decisions. At the time of writing,
png and gif are the ones supported.
=item B<-i> I
Assign the specified CSS class name to images whose environment is
"math". Defaults to "inlinemath".
=item B<-l> I
Assign the specified CSS class name to images whose environment is
"displaymath". Defaults to "displaymath".
=item B<-p> I
Add this string to the LaTeX preamble when generating the equations. For
example, "string" may be a \usepackage{} command. Note that if you need this
for only a few equations, you can also write EEQ PREAMBLE="..."E in the
htex file.
=item B<-r> I
Set resolution of output images, larger numbers produce larger
images. 100 dpi is default. This is most often a bit larger than
surrounding text, but as LaTeX output is really intended for hires
output, details will often disappear at lower resolutions. Do some
experimenting. This option can also be set indivdually for each equation by
writing EEQ DPI="..."E in the htex file.
=item B<-s> I
Set oversampling factor. Larger values will increase antialiasing verbosity,
but is slower. The default is 4. A value of 1 turns off antialiasing, which I
don't recommend.
=item B<-t>
Disable transparent background. With this option, the background colour (-b
option) is solid.
=item B<-u> I
Set absolute url to the image files folder. Use this together with -d option if
you can't use relative links for some reason.
=item B<-v>
Verbose mode, give extra feedback. Gladtex is pretty silent without.
=back
=head1 eqn2img UTILITY
The gladTeX script just parses your html-code and feeds the equations
to the C program eqn2img. This takes care of running LaTeX, dvi2ps and
ghostscript. Furthermore, it finds the baseline of the equation (guided
by a dot that is inserted into the equation), antialiases and writes
the image in the final format. All this is independent from the gladTeX
script, for instance you may write
echo '\sqrt{2}' | eqn2img > sqrt.png
to produce an image of the squareroot of two. For normal operation of
gladTeX, you never use this utility directly, but in any case, here are
(some of) the options.
=over
=item B<-f> I
Use the specified image format in output files. If "format" is just a question
sign "?", eqn2img will print a list of supported formats and quit.
=item B<-s> I
Set oversampling factor (see description of same option for gladTeX).
=item B<-o> I
Set output filename. Without this option, the image is written to stdout.
=item B<-c> I
Set foreground colour in RGB manner.
=item B<-b> I
Set background colour in RGB manner.
=item B<-t>
Turn transparency off.
=item B<-v>
Verbose mode, give some feedback.
=back
All messages are written to stderr. Furthermore, a text string
specifying the dimensions is written to stdout, unless the image is
being written to stdout. In this case, the dimension string is written
to stderr.
Note that eqn2img will only process one file at a time.
=head1 PARSING DETAILS
Gladtex is not case sensitive, so EeQE is allright. Any EeqE
tag must be closed by a E/eqE. Whitespace between "Eeq" and "E"
is allowed. Certain options (such as "COLOR=...") may be present in the tag,
see the Options section above. Whitespace is not allowed anywhere else, so
"E eqE", "E /eqE" and "E/eq E" are all illegal. I'm
not quite sure how this agrees with html standards/conventions.
=head1 THANKS
I am grateful to all users who have provided feedback. The current
version of gladTeX incorporates suggestions from a number of helpful
users.
=head1 COPYRIGHT
Project homepage at http://gladtex.sourceforge.net
Copyright (C) 1999-2010 Martin G. Gulbrandsen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at
your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
gladtex-1.4.2/todo 0000664 0000000 0000000 00000000361 12352307253 0014040 0 ustar 00root root 0000000 0000000 To Do's
=======
* eqn2img: no dvips/ghostscript-dependency
* allow configurable regular expressions for excluding certain kinds of LaTeX
equations automatically
* consider e.g. \begin{cases} ... \end{cases} (not readable in one line)