Showing posts with label latex. Show all posts
Showing posts with label latex. Show all posts

Sunday, January 19, 2025

How to Abbreviate Author Names in IEEEbib.bst

When working with IEEE references in BibTeX, the IEEEbib.bst style is commonly used for IEEE conferences and journals. However, by default, this style formats author names in full (e.g., "John Smith" rather than "J. Smith"). If you'd like to abbreviate the first name to its initial, you can modify the IEEEbib.bst file by adjusting the way author names are formatted. For that you just need to modify the format.names function.

Find the format.names function in the IEEEbib.bst file. It looks like this:

FUNCTION {format.names}
{ 's :=
  #1 'nameptr :=
  s num.names$ 'numnames :=
  numnames 'namesleft :=
    { namesleft #0 > }
    { s nameptr "{ff~}{vv~}{ll}{, jj}" format.name$ 't :=
      nameptr #1 >
{ namesleft #1 >
    { ", " * t * }

Just replace {ff~} with {f.~} in the 7th line to abbreviate first names, i.e.

    { s nameptr "{f.~}{vv~}{ll}{, jj}" format.name$ 't :=

Friday, November 22, 2024

Brighten an \includeimage image in LaTeX Using decodearray without modifying the file

You can adjust the brightness of \includegraphics images in LaTeX without editing them!

The decodearray option in the graphicx package allows you to modify the appearance of images directly within your document.
This is especially useful if you need to tweak image brightness directly in your document without relying on external image editing tools.
The decodearray feature relies on PDF features supported by modern LaTeX engines  such as LuaLaTeX or XeLaTeX. 

\documentclass{article}
\usepackage{graphicx}
\begin{document}

% Original RGB image
\section*{Original Image}
\includegraphics[width=0.5\textwidth]{example-image.jpg}

% Brightened image using decodearray
\section*{Brightened RGB Image}
\includegraphics[width=0.5\textwidth, decodearray={0.2 0.5   0.2 0.5   0.2 0.5}]{uiskentuie_standing_stone.png}


\end{document}


In the example decodearray={0.2 0.5    0.2 0.5    0.2 0.5} maps the original range [0, 1] for each one of the three RGB channels to a narrower, brighter range [0.2, 0.5].

source: https://tex.stackexchange.com/questions/29227/can-includegraphics-be-used-to-change-an-image-color/150219#150219


Friday, October 8, 2021

pandoc: quite good conversion from Latex to docx with references and preserving tikz figures

This works surprisingly well, with all the figures and even rendering the BibTex references: 

> pandoc -C -s main.tex --natbib -o main.docx 

this will produce a document with citations using the  (Author, year) format, to produce citations with a numeric format download the ieee.csl file and call:  

> pandoc -C -s main.tex --natbib --csl=ieee.csl  -o main.docx  


To preserve tikz figures a specialized tikz-to-png filter is needed.  It should be downloaded in the current directory and use the call: 

> pandoc -C -s main.tex --natbib --csl=ieee.csl  --from latex+raw_tex --lua-filter=tikz-to-png.lua -o main.docx  


Figure numbers and captions are not preserved (for obscure reasons), however  table numbering can be  preserved using the document type  -t odt+native_numbering  or  -t docx+native_numbering. 

> pandoc -C -s main.tex --natbib --csl=ieee.csl  --from latex+raw_tex --lua-filter=tikz-to-png.lua -t docx+native_numbering -o main.docx  


Cross-references to sections and figures tables can be recovered with the resolve-references filter but the final format won't be great

> pandoc -C -s main.tex --natbib --csl=ieee.csl  --from latex+raw_tex --lua-filter=tikz-to-png.lua --lua-filter=resolve-references.lua -t docx+native_numbering -o main.docx  


Sources: 
https://waterprogramming.wordpress.com/2018/08/26/converting-latex-to-ms-word-docx-almost-perfectly/
https://tex.stackexchange.com/questions/268196/how-to-convert-latex-to-word-using-pandoc-and-keep-citations-as-numeral

Thursday, September 2, 2021

Conditional formatting LaTeX tables depending on cell values

A package for generating conditional formatted LaTeX tables that extends the one proposed in a post by Siavoosh Payandeh Azad. I've just extended it with the command \gradientd for a divergent colormap. There are also several other solutions discussed in this stackexchange post. The example can be seen in Overleaf here.


The code for generating the table

\documentclass[table]{article}
\usepackage{highlight}

\begin{document}

% For a 2 color palette
% \gradientcell{cell_val}{min_val}{max_val}{colorlow}{colorhigh}{opacity} 

% For a 3 color/divergent palette
% \gradientcelld{cell_val}{min_val}{mid_val}{max_val}{colorlow}{colormid}{colorhigh}{opacity}

% Configure a shorthand macro
\newcommand{\g}[1]{\gradientcelld{#1}{-3}{0}{3}{red}{white}{green}{70}}

\begin{tabular}{l|ccccc}
{$\sigma$} &  40  &   80  & 100  &   200 &  800 \\
\hline
0  & \g{ 0.87} & \g{ 0.84} & \g{ 1.04} & \g{ 1.34} & \g{-4.30} \\
5  & \g{ 0.38} & \g{ 0.22} & \g{ 0.33} & \g{ 0.58} & \g{-2.18} \\
10 & \g{ 0.29} & \g{ 0.04} & \g{ 0.11} & \g{ 0.48} & \g{-0.67} \\
25 & \g{-0.05} & \g{-0.34} & \g{-0.39} & \g{-0.48} & \g{-0.53} \\
50 & \g{ 0.04} & \g{-0.18} & \g{-0.13} & \g{-0.08} & \g{ 0.11} \\
\end{tabular}

\end{document}

The package highlight.sty  implement these commands  

%% Siavoosh Payandeh Azad Jan. 2019
%% modified by Gabriele Facciolo Sep. 2021
\ProvidesPackage{highlight}[Cell background highlighting based on user data]
\RequirePackage{etoolbox}
\RequirePackage{pgf} % for calculating the values for gradient
\RequirePackage{xcolor} % enables the use of cellcolor make sure you have [table] option in the document class 

%======================================
% For a 2 color palette
% \gradientcell{cell_val}{min_val}{max_val}{colorlow}{colorhigh}{opacity} 
\newcommand{\gradientcell}[6]{
    % The values are calculated linearly between \midval and \maxval
    \ifdimcomp{#1pt}{>}{#3 pt}{\cellcolor{#5!100.0!#4!#6}#1}{
    \ifdimcomp{#1pt}{<}{#2 pt}{\cellcolor{#5!0.0!#4!#6}#1}{
         \pgfmathparse{int(round(100*(#1/(#3-#2))-(#2 *(100/(#3-#2)))))}
        \xdef\tempa{\pgfmathresult}
        \cellcolor{#5!\tempa!#4!#6}#1
    }}
 }
%======================================

%======================================
% For a 3 color/divergent palette % \gradientcelld{cell_val}{min_val}{mid_val}{max_val}{colorlow}{colormid}{colorhigh}{opacity} \newcommand{\gradientcelld}[8]{ \xdef\lowvalx{#2}% \xdef\midvalx{#3}% \xdef\maxvalx{#4}% \xdef\lowcolx{#5}% \xdef\midcolx{#6}% \xdef\highcolx{#7}% \xdef\opacityx{#8}% % The values are calculated linearly between \midval and \maxval \ifdimcomp{#1pt}{>}{\maxvalx pt}{\cellcolor{\highcolx!100.0!\midcolx!\opacityx}#1}{ \ifdimcomp{#1pt}{<}{\midvalx pt}{% \ifdimcomp{#1pt}{<}{\lowvalx pt}{\cellcolor{\midcolx!0.0!\lowcolx!\opacityx}#1}{ \pgfmathparse{int(round(100*(#1/(\midvalx-\lowvalx))-(\lowvalx*(100/(\midvalx-\lowvalx)))))}% \xdef\tempa{\pgfmathresult}% \cellcolor{\midcolx!\tempa!\lowcolx!\opacityx}#1% }}{ \pgfmathparse{int(round(100*(#1/(\maxvalx-\midvalx))-(\midvalx*(100/(\maxvalx-\midvalx)))))} \xdef\tempb{\pgfmathresult}% \cellcolor{\highcolx!\tempb!\midcolx!\opacityx}#1% }} }
%======================================

Friday, February 12, 2021

reduce the size of a pdf file compressing its figures


To reduce the size of a PDF file in linux of mac you'll need ghostscript (which in mac can be installed  with: brew install ghostscript). The following command line will generate a smaller file:  

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen \
   -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf   input.pdf


    Different levels of compression can be obtained changing the option -dPDFSETTINGS:
  • -dPDFSETTINGS=/screen lower quality, smaller size. (72 dpi)
  • -dPDFSETTINGS=/ebook for better quality, but slightly larger pdfs. (150 dpi)
  • -dPDFSETTINGS=/prepress output similar to Acrobat Distiller "Prepress Optimized" setting (300 dpi)
  • -dPDFSETTINGS=/printer selects output similar to the Acrobat Distiller "Print Optimized" setting (300 dpi)
  • -dPDFSETTINGS=/default selects output intended to be useful across a wide variety of uses, possibly at the expense of a larger output file

source: https://askubuntu.com/questions/113544/how-can-i-reduce-the-file-size-of-a-scanned-pdf-file

Saturday, February 23, 2019

Latex code and other tools for making neural networks diagrams


 PlotNeuralNet generates tikz code (for Latex) for illustrating a network architectures




NN-SVG is an online tool for illustrating simple architectures and that generates SVG code

Tensorspace.js is a web-based tool that takes keras network definitions and produces beautiful 3D representations on the browser that are also functional!

Netscope is a web-based tool for visualizing neural network architectures for the moment only supports Caffe's prototxt format




Have a look at the stackexchange thread about this topic: https://datascience.stackexchange.com/questions/12851/how-do-you-visualize-neural-network-architectures

Sources:
https://github.com/HarisIqbal88/PlotNeuralNet
http://alexlenail.me/NN-SVG/LeNet.html
https://tensorspace.org/html/docs/startHello.html
http://ethereon.github.io/netscope/quickstart.html
https://www.draw.io/ (for manual drawing from elementary shapes)

Wednesday, April 19, 2017

Stop TeXShop memory leak

Long TeXShop writing sessions (several weeks in my case) reveal that TeXShop leaks memory. I ended up with a 5Gb process without any open file!
This seems to be an old incomprehensible issue but it has a simple solution, just run the following line in your terminal

   defaults write TeXShop ReleaseDocumentClasses 0

If you want to check the status of the variable before changing it:

   defaults read TeXShop ReleaseDocumentClasses

Source: https://sourceforge.net/p/texshop/bugs/87/?SetFreedomCookie

Sunday, March 12, 2017

Fixing textext 0.4.4 in Inkscape 0.91 with OSX

textext is a great Inkscape extension that allows to incrustante LaTeX formulas in the drawings. However, it seems that textext was last updated in 2010 (v0.4.4) and since then some python calls to the md5 package have become deprecated.
This is obviously an issue for recent OS. 
Traceback (most recent call last):
  File "textext.py", line 210, in cb_ok
    self.callback(self.text, self.preamble_file, self.scale_factor)
  File "textext.py", line 369, in
    converter_cls, old_node))
  File "textext.py", line 387, in do_convert
    new_node = converter.convert(text, preamble_file, scale_factor)
  File "textext.py", line 879, in convert
    return PdfConverterBase.convert(self, *a, **kw)
  File "textext.py", line 750, in convert
    self.tex_to_pdf(latex_text, preamble_file)
  File "textext.py", line 727, in tex_to_pdf
    exec_command(['pdflatex', self.tmp('tex')] + latexOpts)
  File "textext.py", line 592, in exec_command
    raise RuntimeError("Command %s failed: %s" % (' '.join(cmd), e))
RuntimeError: Command pdflatex /var/folders/2y/h0000gn/T/tmpUcu75l/tmp.tex -interaction=nonstopmode -halt-on-error failed: [Errno 2] No such file or directory

Sunday, October 14, 2012

Download/backup BibTeX library from CiteULike, including all the attached PDF

CiteULike is a convenient solution for bibliographic management, but sometimes an off-line replica of the bibliography is also needed. This can be achieved by exporting the CiteULike library in BibTeX format, furthermore BibDesk (and probably other managers too) can be synchronized directly with the CiteULike server.

While it is easy to export a .bib file from CiteULike, downloading all the attached files and having the .bib linking to the downloaded files is a different story.

BibTeX and JSON exports of the CiteULike library can be retrieved from:
  http://www.citeulike.org/json/user/USERNAME
  http://citeulike.org/bibtex/user/USERNAME
The BibTeX export can be read directly into a bibliographic manager, but the JSON export contains more information than the .bib, in particular it contains the location of the attached PDFs. So the idea of the Python script linked below is to do the following
  1. download the CiteULike library in BibTeX and JSON formats
  2. parse the JSON export and download all the attachments
  3. modify the .bib file to include links to the downloaded copies of the attachments
the links in the .bib file should work for BibDesk and JabRef.

Before running the script:
  • setup CITEULIKE_USERNAME and CITEULIKE_PASSWORD variables in the script
  • verify you have wget and pybtex installed
Download the Python script:  citeulike_backup.zip

http://wiki.citeulike.org/index.php/Importing_and_Exporting#JSON


Gory details from http://wiki.citeulike.org/index.php/Importing_and_Exporting#JSON:
# save session cookies
> wget -O /dev/null --keep-session-cookies  --save-cookies cookies.txt --post-data="username=xxxx&password=yyyy&perm=1" http://www.citeulike.org/login.do
# download bibtex with private comments and download an attachment
> wget -O export.bib --load-cookies cookies.txt http://www.citeulike.org/bibtex/user/xxxx
> wget --load-cookies cookies.txt http://www.citeulike.org//pdf/user/xxxx/article/123456/891011/some_99_paper_123456.pdf

Friday, May 18, 2012

Convert PDF presentations to Keynote

PDF to Keynote is a free tool for converting PDF-based presentations (e.g., made using LaTeX with Beamer) into Apple's Keynote format. Once translated into Keynote format, every page of the original PDF becomes an image on its own slide, so no further edition is possible.
The advantages of presenting PDFs using Keynote include: the presenter display, rehearsal support, and notes visible only to the presenter.

Source: http://www.cs.hmc.edu/~oneill/freesoftware/pdftokeynote.html

Saturday, November 5, 2011

Minted: Highlighted source code in LATEX

Minted is a LaTeX package that facilitates expressive syntax highlighting using the powerful Pygments library. The package provides options to customize the highlighted source code output.
The example below shows how C code is highlighted,  and the output is shown at right:

\documentclass{article}
\usepackage{minted}

\begin{document}

\begin{minted}{c}
int main()
{
  printf("hello, world");
  return 0;
}
\end{minted}

\end{document}

Pygments also provides a command line interface pygmentize, among the possible output formats there are HTML, RTF, LaTeX and ANSI sequences.
For command line highlighting a solid alternative to Pygments is GNU Source-highlight.



Source: http://mirrors.ircam.fr/pub/CTAN/macros/latex/contrib/minted/minted.pdf
A couple of on-line highlighters: http://www.hilite.me/http://quickhighlighter.com/

Tuesday, November 1, 2011

LaTeX: Verbatim code on a box with background

The code that follows defines the
  verbcode environment, which is handy to include in a LaTeX document a verbatim code box with a fancy colored background as seen shown in the figure. This code snip produces the figure shown.

\documentclass[11pt]{article}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% verbatim boxed text \usepackage{fancyvrb,fancybox,calc} \usepackage[svgnames]{xcolor} \newenvironment{verbcode}{\VerbatimEnvironment% \noindent % {\columnwidth-\leftmargin-\rightmargin-2\fboxsep-2\fboxrule-4pt} \begin{Sbox} \begin{minipage}{\linewidth-2\fboxsep-2\fboxrule-4pt} \begin{Verbatim} }{% \end{Verbatim} \end{minipage} \end{Sbox} \fcolorbox{black}{LightGray}{\TheSbox} }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document} Here is some some code \begin{verbcode} $ run_me.sh param1 \ + ]0 \end{verbcode} \end{document}

Sources:
http://tex.stackexchange.com/questions/18322/using-fancyvrb-verbatim-environment-from-within-newenvironment
http://groups.google.com/group/latexusersgroup/browse_thread/thread/c8c2e5dd1e9ff5cf
LaTeX code highlighted using: http://www.hilite.me/

Saturday, March 5, 2011

Beamer Appendix slides, and controlling frame number

The following example LaTeX document shows how to manipulate the frame counter.

\begin{document}


% Regular slides here


% After your last numbered slide
%\appendix % OPTIONAL
\newcounter{finalframe}
\setcounter{finalframe}{\value{framenumber}}


% Backup slides here


\setcounter{framenumber}{\value{finalframe}}
\end{document}


The 'plain' option removes the footline and frame counter

\frame[plain]{
\frametitle{TITLE}
   %TEXT
}

Source: http://www.stanford.edu/~dgleich/notebook/2009/05/appendix_slides_in_beamer_cont_1.html

Monday, October 25, 2010

Including videos in PDF using pdflatex

The mandatory reference for this topic is: http://pages.uoregon.edu/noeckel/PDFmovie.html

The summary is that, the movie15 parckages allows to produce a PDF files with links to videos and animations. The videos must be located on the same directory as the PDF, and for building pdflatex must be invoked several times (4 in my case). As a result the movie is encapsulated in the PDF file, and in order to view the embedded movie, you need to open it with Adobe Reader or Acrobat.


\documentclass[12pt,landscape]{article}
\usepackage{geometry}
\geometry{verbose,letterpaper}
\usepackage{movie15}
\usepackage{hyperref}


\begin{document}
    \includemovie[ poster,  text={Loading Video} ]{6cm}{6cm}{Circle-m-increase3.mp4}
    % ALSO WORKS WITH .avi AND .mov IN OSX
\end{document}

Thursday, September 16, 2010

Bibtex styles: alpha + abbrv = alphaabbr

When using the alpha style for bibtex I came across the following problem.
Almost every entry in my bibliography file have abbreviated author's names and they appear like this:

[KK90] K.S.Narendra and K.Parthsarathy. Identification and control of dynamical system using neural networks.  IEENN, 1(1):4–27, 1990. 

However in some rare occasions the entry contain the complete author's name, and the entry becomes unpleasantly long:

[dlVP79] Charles Louis Xavier Joseph de la Vall´ee Poussin, 1879. A strong form of the prime number theorem,  19th century. 

I've searched across the bibtex styles and there is no style that suits my needs, so I had to make my own style which produces:

[dlVP79] C.L.X.J. de la Vall´ee Poussin, 1879. A strong form of the prime number theorem,  19th century. 


Bibliography style: alphaabbr
It is exactly the alpha style (i.e. citations like [dlVP79]) but without full names 
in the bibliography section.

* This is done by changing the NAME_FULL flag in btxbst.doc here is the difference:
+++ btxbst.doc 2010-09-16 17:14:50.000000000 +0200
@@ -95,7 +95,7 @@
 % alpha style (sorted short alphabetics)
 #   define LAB_ALPH 1
 #   define SORTED 1
-#   define NAME_FULL 1
+#   define NAME_FULL 0
 #   define ATIT_LOWER 1
 #   define MONTH_FULL 1
 #   define JOUR_FULL 1

* Then compile the style:
cpp -P -DALPHA btxbst.doc alphaabbr.bst

* Use it as always:   \bibliographystyle{alphaabbr}

Thursday, August 19, 2010

Convert ps to pdf without compressing the images

This script converts a ps file to pdf

#/bin/sh
ps2pdf -sPAPERSIZE=a4 \
-dMaxSubsetPct=100 -dCompatibilityLevel=1.3 \
-dSubsetFonts=true -dEmbedAllFonts=true \
-dAutoFilterColorImages=false \
-dAutoFilterGrayImages=false \
-dColorImageFilter=/FlateEncode \
-dGrayImageFilter=/FlateEncode \
-dMonoImageFilter=/FlateEncode \
"$1" "$1.pdf"

Monday, August 9, 2010

LaTeX coffee stains

This is a package that allows to add coffee stains to LaTeX documents, found the reference here: http://divisbyzero.com/2010/07/13/coffee-stains-and-the-simpsons-in-your-latex-document/.  In the same page there is a reference to The Simpsons package, it allows to insert The Simpsons characters into LaTeX documents.

Saturday, July 10, 2010

Include Symbols and Equations in a gnuplot plot.

To write symbols in a gnuplot plot, first the terminal should be configured and the font file loaded
set terminal postscript eps enhanced "Times-Roman" fontfile "cmex10.pfb"


in the file cmex10.pfb is loaded from the current directory, and the enhanced option enables subindices _  and superindices ^ as in LaTeX.

Each symbol is written by calling the escape sequence  {/Symbol w}. In this example
set xlabel "frequency {/Symbol w}"
w will be rendered as $\omega$.

A complete example: 

# Color plot
set terminal postscript eps color enhanced "Times-Roman" fontfile "cmr10.pfb"
# B&W plot
#set terminal postscript eps enhanced "Times-Roman" fontfile "cmex10.pfb"


set output "plot.eps"


# the image will be resized
set size 0.5,0.4


# set the range of the image
set xrange [-pi:pi]


# remove the souronding borders
set border 3
set xtics nomirror
set ytics nomirror


#show vertical grid 
set grid x


#axis labels
set xlabel "2{/Symbol pw}/N"
set ylabel "penalty" 
set ylabel "decay of |A(i{/Symbol w})|" 
set xtics ( "-{/Symbol p}" -pi, "-{/Symbol p}/2" -pi/2, "0" 0, "{/Symbol p}/2" pi/2, "{/Symbol p}" pi)


#definition of the function
f(x)=abs(x)
f1(x)=abs(x**(1.9))
f2(x)=abs(x**(0.4))


### ls: selects the linestyle
plot f(x) lw 3 title "|{/Symbol 2pw}/N|",\
f1(x) lw 3 title "|{/Symbol 2pw}/N|^{1.9}" 


References:

Thursday, April 22, 2010

LaTex, equations for Inkscape, OpenOffice and Others

I'm using MacTeX (http://www.tug.org/mactex/) for writing, it includes the TeX Live and the TeXShop editor.
Other utilities that I find quite useful are: