{"id":13545421,"url":"https://github.com/narimiran/tably","last_synced_at":"2025-03-17T05:32:50.029Z","repository":{"id":115375850,"uuid":"106158886","full_name":"narimiran/tably","owner":"narimiran","description":"Python command-line script for converting .csv data to LaTeX tables","archived":false,"fork":false,"pushed_at":"2018-12-30T08:01:16.000Z","size":90,"stargazers_count":217,"open_issues_count":3,"forks_count":14,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-15T04:46:09.287Z","etag":null,"topics":["cli","command-line","csv","latex","python","python3","table"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/narimiran.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-10-08T07:46:22.000Z","updated_at":"2025-03-04T13:03:36.000Z","dependencies_parsed_at":"2023-03-10T03:00:23.544Z","dependency_job_id":null,"html_url":"https://github.com/narimiran/tably","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/narimiran%2Ftably","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/narimiran%2Ftably/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/narimiran%2Ftably/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/narimiran%2Ftably/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/narimiran","download_url":"https://codeload.github.com/narimiran/tably/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243847060,"owners_count":20357317,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","command-line","csv","latex","python","python3","table"],"created_at":"2024-08-01T11:01:02.458Z","updated_at":"2025-03-17T05:32:46.677Z","avatar_url":"https://github.com/narimiran.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# Tably\n\nPython script for converting .csv data to LaTeX tables.\n\n\n# Features\n\n* easy to use - just provide a .csv file\n* optionally escapes commonly used special LaTeX characters, such as `$`, `\u0026`, `%`, etc.\n* user-defined separators - comma, tab, semicolon, etc.\n* units for each column can be specified\n* possible to define table caption and label\n* columns' alignments can be customized\n* can be used on multiple .csv files at the same time\n* table can be added to the existing .tex file\n* can generate only the fragment inside a tabular environment for inserting into another tex file\n* when working with multiple .csv files, can optionally save each table in a different file\n\n\n# Requirements\n\nPython 3.4+\n\nIt uses `booktabs` package for creating the tables (nicer looking tables than the default `tabular`), which is included in TeXLive distribution and should be automatically installed in MiKTeX distribution.\n\n\n# Installation\n\nFor a test run all you need to do is download the file [`tably.py`](tably.py) and put it in the directory where you would like to use it and run it by typing:\n```bash\n$ python tably.py filename.csv [arguments]\n```\n\nIf you wish to use it repeatedly, a good idea would be to make it executable and add it to your $PATH, which simplifies usage and makes it possible to use it in any directory:\n```bash\n$ tably filename.csv [arguments]\n```\n\n\n# Usage\n\nSee the folder [examples](examples/) for the input files used in the following examples.\n\nThe most basic example:\n```bash\n$ tably examples/example1.csv\n```\n\noutputs to console:\n```tex\n% \\usepackage{booktabs} % move this to preamble and uncomment\n\n\\begin{table}[htb]\n    \\centering\n    \\begin{tabular}{@{}cccc@{}}\n        \\toprule\n        Name \u0026 Qty \u0026 Price per kg \u0026 Price \\\\\n        \\midrule\n        Apples \u0026 10.2 \u0026 5 \u0026 51.0 \\\\\n        Bananas \u0026 7.3 \u0026 11 \u0026 80.3 \\\\\n        Cherries \u0026 5.7 \u0026 30 \u0026 171.0 \\\\\n        Dates \u0026 3.5 \u0026 90 \u0026 315.0 \\\\\n        Eggs \u0026 6.4 \u0026 2 \u0026 12.8 \\\\\n        \\bottomrule\n    \\end{tabular}\n\\end{table}\n```\nwhich is ready to be copied to your existing LaTeX document.\n\nIf you want the output to be appended to your existing .tex file, use the option `-o filename.tex`.\nIf you want to create a new file, you probably want to include a preamble too (so the new .tex document is ready to be build as .pdf), which can be done by passing the `-p` option (along with specifying outfile as above).\n\nAll options can be seen by using `-h` or `--help`:\n```bash\n$ tably -h\n```\n\n```\nusage: tably [-h] [-a ALIGN] [-c CAPTION] [-i] [-k SKIP] [-l LABEL] [-n]\n             [-o OUTFILE] [-oo [PATH [PATH ...]]] [-p] [-s SEP]\n             [-u UNITS [UNITS ...]] [-e] [-f] [-ff] [-r]\n             files [files ...]\n\nCreates LaTeX tables from .csv files\n\npositional arguments:\n  files                 .csv file(s) containing the data you want to export.\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -a ALIGN, --align ALIGN\n                        Alignment for the columns of the table. Use `l`, `c`,\n                        and `r` for left, center and right. Either one\n                        character for all columns, or one character per\n                        column. Default: c\n  -c CAPTION, --caption CAPTION\n                        Caption of the table. Default: None\n  -i, --no-indent       Pass this if you do not want to indent LaTeX source\n                        code with 4 spaces per float. No difference in the\n                        final result (pdf). Default: False\n  -k SKIP, --skip SKIP  Number of rows in .csv to skip. Default: 0\n  -l LABEL, --label LABEL\n                        Label of the table, for referencing it. Default: None\n  -n, --no-header       By default, the first row of .csv is used as a table\n                        header. Pass this option if there is no header.\n                        Default: False\n  -o OUTFILE, --outfile OUTFILE\n                        Choose an output file to save the results. The results\n                        are appended to the file (added after the last line).\n                        Default: None, prints to console.\n  -oo [PATH [PATH ...]], --separate-outfiles [PATH [PATH ...]]\n                        When multiple .csv files need to be processed, pass\n                        -oo to save each individual table in a separate .tex\n                        file. To specifiy each individual output file, pass a\n                        list of filenames after -oo. Alternatively, pass a\n                        directory that will store all the output files. If no\n                        filename/directory is passed after -oo, filenames of\n                        .csv files will be used (with .tex extension).\n  -p, --preamble        If selected, makes a whole .tex document (including\n                        the preamble) ready to be built as .pdf. Useful when\n                        trying to make a quick report. Default: False\n  -s SEP, --sep SEP     Choose a separator between columns. If a file is tab-\n                        separated, pass `t` or `tab`. If a file is semicolon-\n                        separated, pass `s`, `semi` or `\\;`.Default: `,`\n                        (comma-separated)\n  -u UNITS [UNITS ...], --units UNITS [UNITS ...]\n                        Provide units for each column. If column has no unit,\n                        denote it by passing either `-`, `/` or `0`. If `--no-\n                        header` is used, this argument is ignored.\n  -e, --no-escape       If selected, do not escape special LaTeX characters.\n  -f, --fragment        If selected, only output content inside tabular\n                        environment (no preamble, table environment, etc.).\n  -ff, --fragment-skip-header\n                        Equivalent to passing -k 1 -n -f (suppress header when\n                        they are on the first row of .csv and pass -f).\n  -r, --replace         If selected and -o or -oo is passed, overwrite any\n                        existing output file.\n```\n\n\u0026nbsp;\n\nMore complex examples:\n\n```bash\n$ tably examples/example1.csv -o examples/table1.tex -p -a lrcr -u / kg $ $ -l tab:ex1 -c \"Prices of breakfasts\"\n```\n\nSaves the output (`-o`) to [examples/table1.tex](examples/table1.tex) file, containing a preamble (`-p`), alignment of the columns (`-a`) in the table is left-right-center-right (`lrcr`), units (`-u`) for each column are provided (`/` represents no unit, same as `0` and `-`), table label (`-l`) is `tab:ex1` and the caption (`-c`) is `Prices of breakfasts`.\nThe final result is at [examples/table1.pdf](examples/table1.pdf).\n\n---\n\n```bash\n$ tably examples/example2.csv -o examples/table2.tex -p -a r -n -k 3\n```\n\nHere the alignment for a whole table is right (`-a r`), there is no header (`-n`) and we skip first three rows of .csv file (`-k 3`).\nThe final result is at [examples/table2.pdf](examples/table2.pdf).\n\n---\n\n```bash\n$ tably examples/example3.csv -ef -ro examples/table3.tex\n```\n\nWhen .csv files contain special LaTeX characters that are supposed to be reserved in the output, the `--no-escape` (`-e`) option suppresses the default escaping.\nTo include the output in a tex file that already contains a tabular environment by calling `\\input{table3.tex}`, only the fragment (`-f`) inside the environment is generated.\nIf the output file already exists, it will be replaced by the output (`-r`).\n\n---\n\n```bash\n$ tably examples/*.csv -oo 1.tex 2.tex 3.tex -p\n```\n\nOutput for each table is saved into a different file with the `--separate-outfiles` (`-oo`) option and an optional list of output file names specified.\nAlternatively, an output directory can be passed after `-oo`.\nIf no file name comes after `-oo`, the same file names for the .csv files will be used (replacing .csv extension with .tex, or appending .tex if no .csv extension is included in the filename).\n\n\n\u0026nbsp;\n\n# FAQ\n\n\u003e There are online tools which can do the same stuff. Why would I use `tably`?\n\nImagine yourself being stranded on a desert island with you laptop, but without internet, and you need to convert all those .csv's to .pdf before you can be rescued...\n\n\u003e Can I pass multiple .csv files all at once?\n\nYou can, and this is best used if the data in all those .csv files is similar - same number of columns, same data types (so you can use the same alignment for all tables), etc. Like multiple outputs of a same software/machine/procedure.\n\nIf your .csv files are different, it might be easier to call `tably` multiple times, one .csv file per call.\n\n\u003e I found a bug and/or have feature request, how can I contact you?\n\nPlease use this project's [issue tracker](https://github.com/narimiran/tably/issues).\nIf you found a bug, please be as detailed as possible to make it easier for me to be able to reproduce it and fix it.\n\n\n# License\n\n[MIT license](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnarimiran%2Ftably","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnarimiran%2Ftably","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnarimiran%2Ftably/lists"}