@@ -45,23 +45,24 @@ def init_repository(
4545 - .vscode/settings.json with LaTeX Workshop configuration
4646 - LTeX dictionary files for spell checking
4747 - hooks/post-commit for gitinfo2 integration
48+ - main.tex if no .tex file exists
4849
4950 Args:
5051 title: Article title
5152 authors: List of author names
5253 group_id: Zotero group ID
5354 force: Overwrite existing files if True
54- main_tex_file: Main .tex filename (auto-detected if None)
55+ main_tex_file: Main .tex filename (auto-detected if None, created if missing )
5556
5657 Returns:
5758 True if successful, False otherwise
5859 """
5960 print_info (f"Initializing repository at: { self .repo_path } " )
6061
61- # Detect or validate main .tex file
62- tex_file = self ._detect_tex_file (main_tex_file )
62+ # Detect or validate main .tex file, create if missing
63+ tex_file = self ._detect_or_create_tex_file (main_tex_file , title , authors , force )
6364 if not tex_file :
64- print_error ("No main .tex file found or specified " )
65+ print_error ("Failed to detect or create main .tex file" )
6566 return False
6667
6768 project_name = self .repo_path .name
@@ -111,27 +112,39 @@ def init_repository(
111112 print_error (f"Failed to initialize repository: { e } " )
112113 return False
113114
114- def _detect_tex_file (self , specified : Optional [str ]) -> Optional [str ]:
115+ def _detect_or_create_tex_file (
116+ self , specified : Optional [str ], title : str , authors : List [str ], force : bool
117+ ) -> Optional [str ]:
115118 """
116- Detect main .tex file in repository
119+ Detect main .tex file in repository or create one if missing
117120
118121 Args:
119122 specified: User-specified filename (takes priority)
123+ title: Article title (for creating new .tex file)
124+ authors: List of author names (for creating new .tex file)
125+ force: Overwrite existing file if True
120126
121127 Returns:
122- Main .tex filename or None if not found
128+ Main .tex filename or None on failure
123129 """
124130 if specified :
125131 tex_path = self .repo_path / specified
126132 if tex_path .exists ():
127133 return specified
128- print_error (f"Specified .tex file not found: { specified } " )
134+ # Specified file doesn't exist - create it
135+ if self ._create_tex_file (specified , title , authors , force ):
136+ return specified
129137 return None
130138
131139 # Auto-detect .tex files
132140 tex_files = list (self .repo_path .glob ("*.tex" ))
133141
134142 if not tex_files :
143+ # No .tex files found - create main.tex
144+ default_name = "main.tex"
145+ print_info (f"No .tex file found, creating { default_name } " )
146+ if self ._create_tex_file (default_name , title , authors , force ):
147+ return default_name
135148 return None
136149
137150 if len (tex_files ) == 1 :
@@ -149,6 +162,94 @@ def _detect_tex_file(self, specified: Optional[str]) -> Optional[str]:
149162 )
150163 return tex_files [0 ].name
151164
165+ def _create_tex_file (
166+ self , filename : str , title : str , authors : List [str ], force : bool
167+ ) -> bool :
168+ """
169+ Create a basic LaTeX article file
170+
171+ Args:
172+ filename: Name of the .tex file to create
173+ title: Article title
174+ authors: List of author names
175+ force: Overwrite if exists
176+
177+ Returns:
178+ True if successful
179+ """
180+ tex_path = self .repo_path / filename
181+
182+ if tex_path .exists () and not force :
183+ print_info (f"{ filename } already exists (use --force to overwrite)" )
184+ return True
185+
186+ # Format authors for LaTeX
187+ authors_latex = " \\ and " .join (authors )
188+
189+ tex_content = f"""\\ documentclass[a4paper,11pt]{{article}}
190+
191+ % Essential packages
192+ \\ usepackage[utf8]{{inputenc}}
193+ \\ usepackage[T1]{{fontenc}}
194+ \\ usepackage{{lmodern}}
195+ \\ usepackage{{amsmath,amssymb,amsthm}}
196+ \\ usepackage{{graphicx}}
197+ \\ usepackage{{hyperref}}
198+ \\ usepackage[margin=1in]{{geometry}}
199+
200+ % Bibliography
201+ \\ usepackage[style=numeric,sorting=none]{{biblatex}}
202+ \\ addbibresource{{references.bib}}
203+
204+ % Git version information
205+ \\ usepackage{{gitinfo2}}
206+
207+ % Title and authors
208+ \\ title{{{ title } }}
209+ \\ author{{{ authors_latex } }}
210+ \\ date{{\\ today}}
211+
212+ \\ begin{{document}}
213+
214+ \\ maketitle
215+
216+ \\ begin{{abstract}}
217+ Your abstract goes here.
218+ \\ end{{abstract}}
219+
220+ \\ section{{Introduction}}
221+
222+ Your introduction goes here.
223+
224+ \\ section{{Methodology}}
225+
226+ Your methodology goes here.
227+
228+ \\ section{{Results}}
229+
230+ Your results go here.
231+
232+ \\ section{{Conclusion}}
233+
234+ Your conclusion goes here.
235+
236+ % Print bibliography
237+ \\ printbibliography
238+
239+ % Git information (optional - appears in footer)
240+ \\ vfill
241+ \\ hrule
242+ \\ small
243+ \\ noindent Git version: \\ gitAbbrevHash{{}} (\\ gitAuthorIsoDate) \\ \\
244+ Branch: \\ gitBranch
245+
246+ \\ end{{document}}
247+ """
248+
249+ tex_path .write_text (tex_content )
250+ print_success (f"Created: { tex_path .relative_to (self .repo_path )} " )
251+ return True
252+
152253 def _create_directories (self ) -> None :
153254 """Create necessary directory structure"""
154255 directories = [
0 commit comments