Skip to content

Commit

Permalink
readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Zereges committed Aug 30, 2016
1 parent 6ecdeae commit c085601
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 11 deletions.
20 changes: 9 additions & 11 deletions LaTeX.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
/*
* This program is licensed under MIT license. For full text of
* the license, see ./LICENSE file.
*/
#define PURPLE_PLUGINS

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <unistd.h>
#include <windows.h>
#include <errno.h>
#ifdef _WIN32
#include <windows.h>
#else
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#endif

#include <glib.h>

Expand Down Expand Up @@ -58,7 +56,7 @@ static char* getdirname(const char const *file)
GetCurrentDirectory(MAX_PATH, result);
return result;
#else
return getcwd(NULL, 0);
return get_current_dir_name();
#endif
}
result = (char*) malloc((occurence - file + 1) * sizeof(char));
Expand Down Expand Up @@ -171,7 +169,7 @@ char* latex_to_png(const char* full_text, size_t from, size_t len)
if (!font_size)
font_size = DEFAULT_FONTSIZE;

fprintf(tex_file, LATEX_FORMAT_STRING, bgcolor, fgcolor, (int) len, full_text + from);
fprintf(tex_file, LATEX_FORMAT_STRING, bgcolor, fgcolor, len, full_text + from);

tmp_dir = getdirname(file_tex);
if (!tmp_dir || chdir(tmp_dir))
Expand Down Expand Up @@ -253,7 +251,7 @@ static gboolean analyze(char **message, size_t from)
if (start >= length || end >= length)
break;

purple_debug_info("LaTeX", "Found occurence in msg '%s' (at %zu to %zu)\n", *message, start, end);
purple_debug_info("LaTeX", "Found occurence in msg '%s' (at %u to %u)\n", *message, start, end);
sbstr_len = end - start - strlen(LATEX_DELIMITER);
if (!(png_file = latex_to_png(*message, start + strlen(LATEX_DELIMITER), sbstr_len)))
{
Expand Down Expand Up @@ -296,7 +294,7 @@ static gboolean analyze(char **message, size_t from)
length = strlen(*message);

from = start + strlen(LATEX_DELIMITER) + img_text_len;
purple_debug_info("LaTeX", "Looking for another occurence beginning at %zu\n", from);
purple_debug_info("LaTeX", "Looking for another occurence beginning at %u\n", from);
}
return TRUE;
}
Expand Down
5 changes: 5 additions & 0 deletions LaTeX.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* This program is licensed under MIT license. For full text of
* the license, see ./LICENSE file.
*/

#include <glib.h>

#define PLUGIN_PREF_ROOT "/plugins/core/latex"
Expand Down
66 changes: 66 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,68 @@
# pidgin-latex
Reimplementation of popular pidgin plugin used to display LaTeX formulas directly to IM chat.

### Requirements
- Latex (in `PATH`)
- [Dvipng](http://savannah.nongnu.org/projects/dvipng/) (in `PATH`)

On windows `dvipng` is usually part of texlive installation, which is what most windows users use.
On unix, if you don't have dvipng installed, use your distro's package manager (*aptitude*, *pacman*) to install it.

Both platforms usually add those programs to `PATH` environment variable automaticaly.

### Usage
Plugin searches for text between `$$` and `$$`. When found, this text is substituted for `%TEXT%` in this file

\documentclass[preview]{standalone}
\usepackage{amsmath}
\usepackage{color}
\usepackage{amsfonts}
\usepackage{amssymb}
\definecolor{bgcolor}{RGB}{%SETTINGS_BG%}
\definecolor{fgcolor}{RGB}{%SETTINGS_FG%}
\begin{document}
\setlength{\\fboxsep}{0pt}
\colorbox{bgcolor}{
\color{fgcolor}
$%TEXT%$
}
\end{document}

Which is then processed by `latex` to create *dvi* file. Such file is then processed with `dvipng` to create `png` image containing desired output. That image is inserted directly into a displayed message.

Plugin is enabled in IM chats, not in group chats (like IRC).

Plugin is configurable directly from pidgin GUI. It has following options
- background color: In format `R,G,B`. It's substituted for `%SETTINGS_BG%`. Default value is white.
- foreground color: In format `R,G,B`. It's substituted for `%SETTINGS_FG%`. Default value is black.
- font size: Desired font size of formula in the image. Default value is 9px.

### Download
Windows users can download plugin from this link.
Unix users have to compile it, package is not available.

### Installation
Place library file (`.dll` or `.so`) to `path-to-pidgin/plugins/` (all users) or `.purple/plugins` (current user) and turn the plugin on in pidgin.

### Compilation
In order to compile the plugin, you have to compile pidgin from sources (at least *libpurple*). See [pidgin wiki](https://developer.pidgin.im/wiki#DevelopmentInformation) for instructions.

Once *libpurple* is compiled, place `LaTeX.c` and `LaTeX.h` to `pidgin-2.x.y/libpurple/plugins` and execute

make LaTeX.so

On windows platform, execute

make -f Makefile.mingw LaTeX.dll

instead.

### ToDo
- Retrieve bgcolor, fgcolor and font size from gtk settings, pidgin preferences or directly from message, whichever has higher priority.
- Figure out how to resolve quite long (1second) Latex and dvipng calls which causes pidgin to stop responding.

### Bugs
Please report any bugs you found to zereges&lt;at&gt;ekirei.cz or message me directly at github. Attach debug widnow output or screenshots if necessary.

### License
This program is licensed under MIT licence. For full text of the license, see `./LICENSE` file in this repository.

0 comments on commit c085601

Please sign in to comment.