Git Product home page Git Product logo

juliaunit's Introduction

juliaunit

LaTeX package to integrate Julia units and calculations (almost) seamlessly.

This package has a long work until it first stable release, so use it by your own risk.

Features

For now, juliaunit allows you to do calculations in Julia using Unitful.jl to manage physical units and typeset it in LaTeX using siunitx, all directly in your LaTeX file.

You can:

  • Do calculation directly in Julia and typeset the result
  • Convert units in the pipe fashion
  • Print the value and the unit of any Unitful.Quantity
  • Choose the number of decimal places
  • Force scientific notation

Be aware:

  • juliaunit rely strongly on the amazing UnitfulLatexify.jl package. That package was updated to use the the new version of siunitx, v3.0. Now, the command \SI was replaced bu \qty. For now, you'll have to update your siunitx package for the package to work. We're working on a way of establishing backward compatibility, but it may take some time.

Examples

\documentclass{article}

\usepackage{juliaunit}

\begin{document}
    % Julia Code from Pythontex.
    \begin{jlcode}
        T = 298.0 * u"K";
        P = 1u"bar";
        n = 1u"mol";
        R = 8.3145 * u"J/mol/K";
        V = n*R*T/P;
    \end{jlcode}

    $ V = \jlunit{V} $, or, in the SI, $ V = \jlunit{V |> upreferred} $. 
    Or maybe in liter, $ V = \jlunit{V |> u"L"} $.

    If you prefer to use less decimal places, you can just do $ V = \jlunit[2]{V |> u"L"} $. 
    Or maybe you want to force scientific notation: $ V = \jlunit[2][true]{V |> upreferred} $.

    To force scientific notation and use all available decimal places, 
    pass $ -1 $ to the first optional argument, like this:
    $ V = \jlunit[-1][true]{V |> upreferred} $.
\end{document}

And the result:

For more information on Unitful.jl resources and facilities, take a look at the documentation.

How to Use

If you already have Julia and LaTeX installed and working, compile the .sty file with

julia generate_sty.jl

It'll install some packages and give you a juliaunit.sty. Put it in the same folder as your .tex file and compile with:

xelatex file.tex
pythontex file.tex
xelatex file.tex # again if needed

or any engine of your choice.

Using arara

If you use arara, here are a possible compilation recipe (add these lines to your LaTeX code):

% arara: xelatex: {interaction: nonstopmode} if changed('tex') || !exists('pytxcode')
% arara: pythontex
% arara: xelatex: {interaction: nonstopmode}
% arara: xelatex: {interaction: nonstopmode} if missing('pdf') || found('log', 'undefined references')

and compile with:

arara file.tex

Again, you can replace xelatex with any engine of your choice (see arara's docs).

With latexmk

PythonTeX also works with latexmk. Take a look at the section 4.6.1 of the documentation. You can also just add this to your .latexmkrc file (see examples).

How it works

This package actually hasn't nothing really new. It uses pythontex to run Julia from LaTeX, and Latexify.jl and UnitfulLatexify.jl to print unities in LaTeX format. However, it lets you focus on your text and forget all these connections.

Contributing

Any contribution is welcome. The project is structured in two main files, juliaunit_template.sty that provides LaTeX interface, and a juliaunit.jl that is the Julia side. However, the actual usable file is juliaunit.sty, which contains LaTeX and Julia code and is produced running generate_sty.jl.

To contribute, fork the repo, clone, and make your changes. Then run generate_sty.jl. Copy or symlink juliaunit.sty to your texmf or project folder. Test and submit your pull request!

License

This project is under GPL v3.0-or-older license, which basically means that you can do everything except turn it into a private product.

Author

Maintained by Heliton Martins.

juliaunit's People

Contributors

hellmrf avatar

Stargazers

ebigram avatar Tallyta Duarte avatar  avatar Elias Carvalho avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.